Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hey Guys, Well ive been racking my brains out over the last 2 days trying to do this final part of my usermanagement system. So far ive finally got most of the password update working. Ive got it to check for existing usernames, then store it to my passwords.txt file. But now i also need to get it to update another 3 data/password files that also include the usernames and passwords. But i cannot work out how to do it, ive tried to call an external script, implement part of a script into my current and nothing seems to be working. Any ideas would be great, thanks! This is what i have;

# # 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 = <>); }

I would like to also somehow print a statement about each file to. eg,
file1.dat; user id found, password updated file2.dat; user id not found, password not updated.
Please Help!

Replies are listed 'Best First'.
Re: User Management System; Password Updating
by apl (Monsignor) on Apr 25, 2008 at 11:23 UTC
    But now i also need to get it to update another 3 data/password files that also include the usernames and passwords.
    That's nice.
    But i cannot work out how to do it, ive tried to call an external script, implement part of a script into my current and nothing seems to be working.

    You haven't told us what you need to do. You haven't shown us what you've tried. You haven't told us why it didn't work.

    Don't show us your entire program, show us what you're trying to do that is not working. Subroutines are Good Things.

    I don't mean to sound harsh, but useless comments make my eyes glaze over...