Difference between revisions of "Manual:DIL Manual/set 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="bpsetpassword"></span>
+
= set_password() =
 +
'''Procedure.''' Sets a player's password.
  
−
  '''Function:'''  <i><!--CODE-->set_password( u : unitptr, s : string ) ;</i><!--ENDCODE-->
+
  set_password(pc : unitptr, pwd : string)
  
−
<!--TERM--> '''u'''
+
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.
−
<!--DEFINITION-->         the unit that you want to set the password of
 
−
<!--TERM-->  '''s'''
 
−
<!--DEFINITION-->        the password you are using to set
 
  
−
This function sets a unit password it only works on Players characters of corse.
+
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.
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
  
−
dilbegin aware do_password (arg:string);
+
== Parameters ==
−
var
+
{| class="wikitable"
−
        prmt:string;
+
! Name !! Type !! Meaning
−
  firstpwd:string;
+
|-
 +
| pc || unitptr || The player.
 +
|-
 +
| pwd || string || The new password, in plain text.
 +
|}
  
−
  i:integer;
+
== Notes ==
−
  tlist:stringlist;
+
* 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.
  
−
code
+
== 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]]
−
 
 
−
</i><!--ENDCODE-->
 
−
<span id="bpsetpassword"></span>
 
−
 
 
−
'''Function:'''  <i><!--CODE-->set_password( u : unitptr, s : string ) ;</i><!--ENDCODE-->
 
−
 
 
−
<!--TERM-->  '''u'''
 
−
<!--DEFINITION-->        the unit that you want to set the password of
 
−
<!--TERM-->  '''s'''
 
−
<!--DEFINITION-->        the password you are using to set
 
−
 
 
−
This function sets a unit password it only works on Players characters of corse.
 
−
'''Example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
dilbegin aware do_password (arg:string);
 
−
var
 
−
        prmt:string;
 
−
  firstpwd:string;
 
−
 
 
−
  i:integer;
 
−
  tlist:stringlist;
 
−
 
 
−
code
 
−
dilend
 
−
 
 
−
 
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 

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 password command 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).

See also