Code.GeekInterview.com
 
Code Samples Perl
 

PassCripting - Crypt Perl Password


Code ResourceAuthor: srinivasaraobora  

Difficulty Level: Beginner

Published: 24th Apr 2009   Read: 3995 times  

Filed in: Perl
Add Comment


 

 

Sponsored Links


 

 

This code show how to crypt the password in perl

 


Sample Code
  1. #!/usr/bin/perl
  2.  
  3. # passcrypt.plx
  4.  
  5. use warnings;
  6.  
  7. use strict;
  8.  
  9.  
  10.  
  11. print "Please enter your password for crypting: ";
  12.  
  13. # See `perldoc -q password' for a better way to do this.
  14.  
  15. chomp(my $passwd = <>);
  16.  
  17.  
  18.  
  19. my $salt = join '',
  20.  
  21.   ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64];
  22.  
  23. $passwd = crypt($passwd, $salt);
  24.  
  25.  
  26.  
  27. # $passwd is now securely stored.
  28.  
  29.  
  30.  
  31.  
  32.  
  33. # Suppose we know that $passwd is a crypted password
  34.  
  35. print "Please enter your password: ";
  36.  
  37. chomp(my $trypass = <>);
  38.  
  39.  
  40.  
  41. unless ($passwd eq crypt($trypass, $passwd)) {
  42.  
  43.   die "You're not who you say you are!";
  44.  
  45. }
  46.  
  47.  
Copyright GeekInterview.com


Next Article: PerlScript Array


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. srinivasaraobora17434

Active Coders

# Coder NameCodes
1. srinivasaraobora5

Refined Tags