Manual:DIL Manual/check password()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:16, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 pc for 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.

See also