Difference between revisions of "Manual:DIL Manual/check password()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfcheckpassword"></span>
+
= check_password() =
 +
'''Function''' (integer). Tells whether a password is a player's password.
  
−
  '''Function:'''  <i><!--CODE-->integer check_password( u : unitptr, s : string ) ;</i><!--ENDCODE-->
+
  check_password(pc : unitptr, pwd : string) : integer
  
−
<!--TERM--> '''u'''
+
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.
−
<!--DEFINITION-->         the unit that you want to check the password of
 
−
<!--TERM-->  '''s'''
 
−
<!--DEFINITION-->        the password you are using to check
 
−
<!--TERM-->  '''Return'''
 
−
<!--DEFINITION-->        Returns an integer TRUE if pcname is the units password FALSE if not
 
  
−
This function checks the string against the units password and returns TRUE
+
== Parameters ==
−
if they match.
+
{| class="wikitable"
−
'''Example:'''
+
! Name !! Type !! Meaning
−
<i><!--CODE-->
+
|-
−
---~---~---~---~---~---~---~---~---
+
| pc || unitptr || The player.
 +
|-
 +
| pwd || string || The password to try, in plain text.
 +
|}
  
−
if (not check_password(pc,arg))
+
== 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.
  
−
</i><!--ENDCODE-->
+
== 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 ==
−
<span id="bfcheckpassword"></span>
+
* [[Manual:DIL Manual/set password()|set_password()]]
−
 
+
* [[Manual:DIL Manual/excmdstr case|excmdstr_case]]
−
'''Function:'''  <i><!--CODE-->integer check_password( u : unitptr, s : string ) ;</i><!--ENDCODE-->
 
−
 
 
−
<!--TERM-->  '''u'''
 
−
<!--DEFINITION-->        the unit that you want to check the password of
 
−
<!--TERM-->  '''s'''
 
−
<!--DEFINITION-->        the password you are using to check
 
−
<!--TERM-->  '''Return'''
 
−
<!--DEFINITION-->        Returns an integer TRUE if pcname is the units password FALSE if not
 
−
 
 
−
This function checks the string against the units password and returns TRUE
 
−
if they match.
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
if (not check_password(pc,arg))
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

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 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