102 lines
3.1 KiB
C
102 lines
3.1 KiB
C
/* /secure/cmds/players/passwd.c
|
|
* from the Dead Souls Object Library
|
|
* passwd
|
|
* created by Descartes of Borg 951202
|
|
*/
|
|
|
|
#include <lib.h>
|
|
#include <flags.h>
|
|
#include <message_class.h>
|
|
#include "include/passwd.h"
|
|
|
|
inherit LIB_DAEMON;
|
|
|
|
mixed cmd(string args) {
|
|
object ob;
|
|
|
|
if( previous_object()->GetForced() )
|
|
return "You cannot be forced to change your password.";
|
|
if( args && args != "" ) {
|
|
if( !archp(previous_object()) )
|
|
return "You may not change other people's passwords.";
|
|
if( !user_exists(args = convert_name(args)) )
|
|
return "No such user exists.";
|
|
ob = find_player(args);
|
|
}
|
|
else ob = previous_object();
|
|
previous_object()->eventPrint("Changing password for " +
|
|
(ob ? ob->GetCapName() :
|
|
capitalize(args)) + " on " +
|
|
mud_name() + ".", MSG_SYSTEM);
|
|
if( previous_object() == ob ) {
|
|
ob->eventPrint("Old password: ", MSG_PROMPT);
|
|
input_to( (: OldPass :), I_NOECHO | I_NOESC, ob);
|
|
}
|
|
else {
|
|
previous_object()->eventPrint("New password: ", MSG_PROMPT);
|
|
input_to( (: NewPass :), I_NOECHO | I_NOESC, ob || args);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void OldPass(string pass, object who) {
|
|
string oldpass;
|
|
|
|
if( who != this_player() ) return;
|
|
if( !pass || pass == "" ) {
|
|
who->eventPrint("\nPassword change failed.", MSG_SYSTEM);
|
|
return;
|
|
}
|
|
oldpass = this_player()->GetPassword();
|
|
if( oldpass != crypt(pass, oldpass) ) {
|
|
who->eventPrint("\nPassword change failed.", MSG_SYSTEM);
|
|
return;
|
|
}
|
|
who->eventPrint("\nNew password: ", MSG_PROMPT);
|
|
input_to((: NewPass :), I_NOECHO | I_NOESC, who);
|
|
}
|
|
|
|
static void NewPass(string pass, mixed who) {
|
|
if( !pass || strlen(pass) < 5 ) {
|
|
this_player()->eventPrint("Password must be at least 5 "
|
|
"characters, password change failed.",
|
|
MSG_SYSTEM);
|
|
return;
|
|
}
|
|
this_player()->eventPrint("\nConfirm: ", MSG_PROMPT);
|
|
input_to( (: ConfirmPass :), I_NOECHO | I_NOESC, who, pass);
|
|
}
|
|
|
|
static void ConfirmPass(string str, mixed who, string newpass) {
|
|
if( str != newpass ) {
|
|
this_player()->eventPrint("Passwords do not match.", MSG_SYSTEM);
|
|
return;
|
|
}
|
|
if( objectp(who) ) who->SetPassword(crypt(newpass, 0));
|
|
else {
|
|
string *lines;
|
|
|
|
who = player_save_file(who);
|
|
lines = explode(unguarded((: read_file, who :)),"\n");
|
|
unguarded((: rm, who :));
|
|
foreach(string line in lines) {
|
|
string val;
|
|
|
|
if( sscanf(line, "Password %s", val) )
|
|
line = "Password \"" + crypt(newpass, 0) + "\"";
|
|
unguarded((: write_file, who, line + "\n" :));
|
|
}
|
|
}
|
|
this_player()->eventPrint("\nPassword changed.", MSG_SYSTEM);
|
|
}
|
|
|
|
string GetHelp(){
|
|
int i;
|
|
string ret = "Syntax: passwd\n";
|
|
if(i = (archp(this_player()))) ret += " passwd <PLAYER>\n";
|
|
ret += "\nThis command allows you to change your password";
|
|
if(i) ret += " or that of the specified player";
|
|
ret += ".\n See also: chfn";
|
|
return ret;
|
|
}
|