Hey Guys, Well im trying to create a user management system using Perl. Ive so far got it add users, and delete users without a problem. But the Update user part is causing me problems galore! So can anyone help me out with some pointers as to why the script is not performing properly please? I am able to input the user i want to update, but sometimes it says my input password is wrong, when its not.. and it also is asking for another input when it shouldn't?

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

This is whatshappening when i try to run it, showing me the encrypted passwords as i input and its reads them too...
---------------------------------------------------------------------- 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

In reply to User management system; file input not working? by jambocool

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.