jambocool has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w print "\n\n\n\n\n\n\n------------------------------------------------- +---------------------"; print "\nWelcome to Jamie's User Management System. \n\nPlease select +the option that you wish to use:\n -a -- To create a new username and + password.\n -u -- To update a users password.\n -d -- To delete a us +er from the system.\n -h -- For more help!\n\n -q -- To quit this sys +tem\n\n "; # Take initial input from user print "\nPlease input your desired first Option --> : "; chomp ($option = <>); # #Determine what option is selected # Add in a new user # if ($option eq "-a") { print "\n\n\n--- Add User Menu --- \n"; print "\nEnter User Name --> : "; chomp ($userName = <>); open my $fh, "<", 'passwords.txt' or die "Can't open password file: $! +"; while (<$fh>) { chomp; ($name,$passwd) = split(/:/); if ($userName eq $name) { print "Sorry That Username already Exists"; print "\nEnter User Name --> : "; chomp ($userName = <>); } } print ("Enter a secret password:"); system ("stty -echo"); $inputline1 = <STDIN>; system ("stty echo"); chop ($inputline1); print ("\nPlease enter your password in again:"); system ("stty -echo"); $inputline2 = <STDIN>; system ("stty echo"); chop ($inputline2); #Verify that password has been entered correctly $outputline = $inputline1 eq $inputline2 ? "\n\nYes, that is the correct password!\n" : "\n\nNo, that is not the correct password.\n"; print ($outputline); #Encrypt the password $salt = $userName; $encryptpw = crypt ($inputline2,$salt); #Write username and password to the passwords.txt file open (FILE, ">>passwords.txt"); print FILE "$userName:$encryptpw\n"; close (FILE); print ("Your Username and Password have been saved!\n"); # Take input from user print "\nPlease input your next Option ( -u,-d,-h,-q ) --> : "; chomp ($option = <>); } # # Update existing user # if ($option eq "-u") { print "\n\n\n--- Update User Password Menu --- \n"; print "\nEnter Your Current User Name --> : "; chomp ($userName2 = <STDIN>); print ("Enter Your Current Password:"); system ("stty -echo"); $inputline3 = <STDIN>; system ("stty echo"); chop ($inputline3); #Encrypt the password $salt = $userName2; $encryptpw2 = crypt ($inputline3,$salt); print "$encryptpw2\n"; open my $fh, "<", 'passwords.txt' or die "Can't open password file: $! +"; while (<$fh>) { chomp; ($name,$passwd) = split(/:/); print "$passwd\n"; if ($encryptpw2 eq $passwd) { print ("\nPlease Enter 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); } elsif ($encryptpw2 ne $passwd) { die ("\n\nYour Passwords Did Not Match, Please Try running the + script again. \n\n"); } if ($newpass eq $newpass2) { #Encrypt the password $salt2 = $userName2; $encryptpw3 = crypt ($newpass2,$salt2); use Tie::File; my $file_name = 'passwords.txt'; tie @array, 'Tie::File', $file_name or die; for (@array) { s/$inputline3/$encryptpw3/g; print ("\n\nYour Username and Password have been updated and s +aved!\n\n"); } untie @array; } elsif ($newpass ne $newpass2) { die ("\n\nYour Passwords Did Not Match, Please Try again. \n\n"); } } # Take input from user print "\nPlease input your next Option ( -u,-d,-h,-q ) --> : "; chomp ($option = <>); }
---------------------------------------------------------------------- Welcome to Jamie's User Management System. Please select the option that you wish to use: -a -- To create a new username and password. -u -- To update a users password. -d -- To delete a user from the system. -h -- For more help! -q -- To quit this system Please input your desired first Option --> : -u --- Update User Password Menu --- Enter Your Current User Name --> : test Enter Your Current Password:teH0wLIpW0gyQ jrsWIWyBMGLdM Your Passwords Did Not Match, Please Try running the script again. % cat passwords.txt jrojas:jrsWIWyBMGLdM test:teH0wLIpW0gyQ
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: User management system; file input not working?
by elmex (Friar) on Apr 20, 2008 at 06:52 UTC | |
|
Re: User management system; file input not working?
by alexm (Chaplain) on Apr 20, 2008 at 14:48 UTC | |
|
Re: User management system; file input not working?
by walto (Pilgrim) on Apr 20, 2008 at 13:27 UTC | |
|
Re: User management system; file input not working?
by apl (Monsignor) on Apr 20, 2008 at 13:13 UTC |