Test a UNIX password : getpwnam « System Functions « Perl






Test a UNIX password

      

    $pass = "password";

    ($encstring) = (getpwnam("stephen"))[1];

    $salt = substr($encstring,0,2);
    $encpass = substr($encstring,2);

    $newencpass = crypt($pass,$salt);

    if($encstring eq $newencpass)
    {
        print "Correct\n";
    }
    else
    {
        print "Incorrect\n";
    }

   
    
    
    
    
    
  








Related examples in the same category

1.To display all the /etc/passwd fields for users passed on the command line
2.Values Returned by getpwnam
3.The getgrnam function retrieves the group file entry corresponding to a particular group name.