Difference between revisions of "Manual:DIL Manual/check password()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = check_password() = | ||
| + | '''Function''' (integer). Tells whether a password is a player's password. | ||
| + | check_password(pc : unitptr, pwd : string) : integer | ||
| − | < | + | Hashes <code>pwd</code> the way [[Manual:DIL Manual/set password()|set_password()]] does and compares it with the player's stored password. It works from any zone. |
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | pc || unitptr || The player. | ||
| + | |- | ||
| + | | pwd || string || The password to try, in plain text. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | TRUE when it is the password, FALSE when it isn't. Only the first 8 characters count, of the stored password and of <code>pwd</code>. It fails, and the zone log says "Unit must be a pc to check password", when <code>pc</code> is an NPC, object or room. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| − | + | * Test <code>pc</code> for null first: on a unit variable that holds null the server crashes. | |
| − | + | * Nothing in the game uses it today. | |
| − | |||
| − | |||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin ask_password(); | |
| − | + | var | |
| − | + | good : integer; | |
| + | code | ||
| + | { | ||
| + | if (self.type != UNIT_ST_PC) | ||
| + | quit; | ||
| + | sendtext("Type your password to go on:<br/>", self); | ||
| + | wait(SFB_CMD, self == activator); | ||
| + | block; | ||
| + | good := check_password(self, excmdstr_case); | ||
| + | if (good) | ||
| + | sendtext("Password accepted.<br/>", self); | ||
| + | else | ||
| + | sendtext("Wrong password.<br/>", self); | ||
| + | quit; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Asks the player for the password and checks it. The answer is typed as a command, so <code>block</code> keeps the game from running it; <code>excmdstr_case</code> keeps its case, as the <code>password</code> command in commands.zon does. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/set password()|set_password()]] | |
| − | + | * [[Manual:DIL Manual/excmdstr case|excmdstr_case]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:16, 14 November 2026
check_password()
Function (integer). Tells whether a password is a player's password.
check_password(pc : unitptr, pwd : string) : integer
Hashes pwd the way set_password() does and compares it with the player's stored password. It works from any zone.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
| pwd | string | The password to try, in plain text. |
Returns
TRUE when it is the password, FALSE when it isn't. Only the first 8 characters count, of the stored password and of pwd. It fails, and the zone log says "Unit must be a pc to check password", when pc is an NPC, object or room.
Notes
- Test
pcfor null first: on a unit variable that holds null the server crashes. - Nothing in the game uses it today.
Example
dilbegin ask_password();
var
good : integer;
code
{
if (self.type != UNIT_ST_PC)
quit;
sendtext("Type your password to go on:<br/>", self);
wait(SFB_CMD, self == activator);
block;
good := check_password(self, excmdstr_case);
if (good)
sendtext("Password accepted.<br/>", self);
else
sendtext("Wrong password.<br/>", self);
quit;
}
dilend
Asks the player for the password and checks it. The answer is typed as a command, so block keeps the game from running it; excmdstr_case keeps its case, as the password command in commands.zon does.