# # Start Update existing user # # Determine that the -u (update) trigger is used if ($option eq "-u") { # Print update user heading print "\n\n\n--- Update User Password Menu --- \n"; print "\nEnter Your Current User Name --> : "; # User inputs username they wish to update. assigned to $userName2 not + to confuse with earlier chomp ($userName2 = <>); # Get user to put in the current password for that username print ("Enter Your Current Password:"); # Use the system to stop echo'ing whats typed up on the screen system ("stty -echo"); # Assign the thier input password as a string $inputline3 $inputline3 = <STDIN>; # Turn echo back on for input to come up system ("stty echo"); chop ($inputline3); # Encrypt the input password again (using thier username as the $salt) + to compare it with the password on file $salt = $userName2; $encryptpw2 = crypt ($inputline3,$salt); # Use open command to open the passwords.txt file as a filehande open my $fh, "<", 'passwords.txt' or die "Can't open password file: $! +"; while ( my $line = <$fh> ) { chomp $line; # Split up and assign the password.txt file into $name = username +and $passwd = encrypted password my ( $name, $passwd ) = split /:/, $line; # Scan through file unless they match usernames next unless $name eq $userName2; # If username found, match input password with password on file (b +oth already encrypted) if ($encryptpw2 eq $passwd) { # If they match, continue to ask for new password print ("\nEnter Your new password:"); system ("stty -echo"); $newpass = <STDIN>; system ("stty echo"); chop ($newpass); print ("\nPlease enter your new password in again:"); system ("stty -echo"); $newpass2 = <STDIN>; system ("stty echo"); chop ($newpass2); } # If password does not match, script dies else { die ("\n\nYour Passwords Did Not Match, Please Try running the scr +ipt again. \n\n"); } # Check to see if new input passwords match if ($newpass eq $newpass2) { # Encrypt the new password and assign it to $encryptpw3 $salt2 = $userName2; $encryptpw3 = crypt ($newpass2,$salt2); # Replace old password with new one stored in file use Tie::File; my $file_name = 'passwords.txt'; # Input file into an array tie @array, 'Tie::File', $file_name or die; for (@array) { # Search for $encryptpw2 and replace with $encryptpw3 s/$encryptpw2/$encryptpw3/g; } untie @array; # If successful print next statement print ("\n\nYour Username and Password have been updated and saved!"); } # Otherwise if new passwords do not match, show and die elsif ($newpass ne $newpass2) { die ("\n\nYour Passwords Did Not Match, Please Try again. \n\n"); } } # Update user finished Take next input from user print "\nPlease input your next Option ( -u,-d,-h,-q ) --> : "; chomp ($option = <>); }
Please Help!file1.dat; user id found, password updated file2.dat; user id not found, password not updated.
In reply to User Management System; Password Updating by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |