Home >> perlfunctions >>Perl function: cryptSyntax:crypt STR, SALTEncrypts STR based on the encrypted version specified by SALT. It's a one way function, meaning there is no corresponding function to decrypt STR once it has been encrypted. Hence, though it cannot be used for cryptography, it can be used to store and check password. When a user enters a password for storage, it is encrypted using a specific salt and stored. When the user enters the password again for authentication, it is again encrypted using the same salt and matched with the previously stored password. If both match, the system recognises the password as correct. Example: print "Enter the string \n"; #read string and remove new line chomp(my $str =The above example takes the input string and salt from the user. The SALT can be any two alphanumerics which are stored in the encrypted string as the first two characters to compare later on. To check if a user entered string matches enc_str, we add the following code to the above example: print "Enter the string to check \n"; chomp(my $chk_str =The crypt functions above uses chk_str and enc_str because SALT is only two characters and the first two characters of enc_str, previously encrypted string are the SALT. A little change in the value of STR or SALT will result in large changes in the resulting encrypted string and decoding it is next to impossible. Perl functions
|
List of all perl functions Perl function : split Perl function: abs Perl function: chomp Perl function: chop Perl function: chr Perl function: eval Perl function: hex Perl function: lc Perl function: lcfirst Perl function: length Perl function: oct Perl function: ord Perl function: shift
|