Viewing file: changepass.pl (3.39 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/perl
###########################################################################
# changepass.pl - Let the user change their password
###########################################################################
require "common.pl";
###########################################################################
# Print header
###########################################################################
if ($button eq $cancel_button) {
&cancel;
} elsif ($remip ne $fromip) {
&diffip;
}
&print_header;
if ($button eq $change_button) {
###########################################################################
# Verify current password
###########################################################################
@username = split(/ /, $sessionid);
$username = $username[0];
dbmopen(%pass, $passdb, 0600) || die "Error opening db $passdb";
$stored = $pass{$username};
$hashed = crypt($curpass, $stored);
if ($hashed ne $stored) {
###########################################################################
# Not their current password
###########################################################################
print $wrong_pass_info;
} elsif ($password ne $pass2) {
###########################################################################
# The new passwords don't match
###########################################################################
print $diff_pass_info;
} elsif (index($password," ") >= 0) {
###########################################################################
# Space in password
###########################################################################
print $pass_invalid_info;
} elsif ($passwd =~ /,/) {
###########################################################################
# Password has a comma in it
###########################################################################
print $pass_invalid_info;
} elsif (!$password) {
###########################################################################
# Blank password
###########################################################################
print $missing_field_info;
} else {
###########################################################################
# Encrypt the new password
###########################################################################
$a = time;
chop($a);
srand($a);
$one = int(rand($a)) + 1;
$two = int(rand($a)) + 1;
$salt = "$one$two";
$hashed = crypt($password, $salt);
$pass{$username} = $hashed;
###########################################################################
# Store it in the database
###########################################################################
dbmopen(%hints, $hintdb, 0600) || die "Error openening db $hintdb";
$hints{$username} = $hint;
dbmclose(%hints);
###########################################################################
# Let them know it worked
###########################################################################
print $pass_change_info;
}
###########################################################################
# Close the database
###########################################################################
dbmclose(%pass);
}
###########################################################################
# Done
###########################################################################
&print_options;
&update_sess;
&print_footer;
|