Difference between revisions of "Manual:DIL Manual/set password()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = set_password() = | |
| + | '''Procedure.''' Sets a player's password. | ||
| − | + | set_password(pc : unitptr, pwd : string) | |
| − | + | The password is stored the classic Unix way, hashed with <code>crypt()</code> with the character's name as the salt. Only the first 8 characters count: "secretpassword" and "secretpa" are the same password. The new password is kept with the character and written to disk when the player is next saved. | |
| − | |||
| − | |||
| − | |||
| − | + | Only a program started in a zone with access level 0 (the fourth column of <code>vme/etc/zonelist</code>) can use it. What counts is the zone of the program's first template, the one that was <code>dilcopy</code>'d or run as a command. Elsewhere the zone log gets "attempt to violate system access security (setpassword)" and the program stops. | |
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| − | + | |- | |
| + | | pc || unitptr || The player. | ||
| + | |- | ||
| + | | pwd || string || The new password, in plain text. | ||
| + | |} | ||
| − | + | == Notes == | |
| − | + | * Players only: on an NPC, object or room the program stops with "Type error in Not a pc unit" in the zone log. | |
| + | * A null unit variable is logged ("set_password with no unit") and nothing changes; so does an empty (null) string. | ||
| + | * It doesn't check the password at all. The <code>password</code> command in commands.zon asks twice and wants 5 to 16 characters. | ||
| + | * If <code>crypt()</code> fails, the old password stays and vme.log says so. | ||
| − | + | == Example == | |
| + | <pre> | ||
| + | dilbegin new_password(pc : unitptr, pwd : string); | ||
| + | code | ||
| + | { | ||
| + | if (pc.type != UNIT_ST_PC) | ||
| + | return; | ||
| + | if ((length(pwd) < 5) or (length(pwd) > 16)) | ||
| + | { | ||
| + | sendtext("A password has 5 to 16 characters.<br/>", self); | ||
| + | return; | ||
| + | } | ||
| + | log("PASSWORD: " + self.name + " changed " + pc.name + "'s password."); | ||
| + | set_password(pc, pwd); | ||
| + | sendtext("Password changed.<br/>", self); | ||
| + | } | ||
dilend | dilend | ||
| + | </pre> | ||
| + | A god sets another player's password and it is logged, as the <code>set</code> command does for its <code>pwd</code> field (set.zon). | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/check password()|check_password()]] | |
| − | + | * [[Manual:DIL Manual/delete player()|delete_player()]] | |
| − | + | * [[Manual:DIL Manual/access|access]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:16, 14 November 2026
set_password()
Procedure. Sets a player's password.
set_password(pc : unitptr, pwd : string)
The password is stored the classic Unix way, hashed with crypt() with the character's name as the salt. Only the first 8 characters count: "secretpassword" and "secretpa" are the same password. The new password is kept with the character and written to disk when the player is next saved.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to violate system access security (setpassword)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
| pwd | string | The new password, in plain text. |
Notes
- Players only: on an NPC, object or room the program stops with "Type error in Not a pc unit" in the zone log.
- A null unit variable is logged ("set_password with no unit") and nothing changes; so does an empty (null) string.
- It doesn't check the password at all. The
passwordcommand in commands.zon asks twice and wants 5 to 16 characters. - If
crypt()fails, the old password stays and vme.log says so.
Example
dilbegin new_password(pc : unitptr, pwd : string);
code
{
if (pc.type != UNIT_ST_PC)
return;
if ((length(pwd) < 5) or (length(pwd) > 16))
{
sendtext("A password has 5 to 16 characters.<br/>", self);
return;
}
log("PASSWORD: " + self.name + " changed " + pc.name + "'s password.");
set_password(pc, pwd);
sendtext("Password changed.<br/>", self);
}
dilend
A god sets another player's password and it is logged, as the set command does for its pwd field (set.zon).