Search code examples
perlpassword-confirmation

perl password confirmation


can anyone give me a sample code for letting a user to enter a password two times and compare them and print a text if they are correct or not, like when we create a new user. Thanks in advance...


Solution

  • From perldoc -f crypt,

    $pwd = (getpwuid($<))[1];
    
    system "stty -echo";
    print "Password: ";
    chomp($word = <STDIN>);
    print "\n";
    system "stty echo";
    
    if (crypt($word, $pwd) ne $pwd) {
        die "Sorry...\n";
    } else {
        print "ok\n";
    }
    

    Modify to suit your needs.