- 论坛徽章:
- 0
|
Perl crypt()函数
-------------------------------------
语法
crypt EXPR,SALT
定义和用法
使用该系统的crypt()函数加密的字符串EXPR。使用SALT的值的数量变化从一个选择的加密版本。需要注意的是没有对等的解密功能。使用这种方式你不能解密被加密的字符串。它通常使用的一种方法,首先对字符串进行加密,然后加密的密码加密的字符串进行比较。 If you're using it in this form, then consider supplying the encrypted password as the SALT.如果您使用的是这种形式,然后再考虑提供加密的密码的SALT。
反回值
加密的字符串
例子
这里有一个例子可以让你运行这个程序无论谁都不知道自己的密码:
#!/usr/bin/perl
$pwd = (getpwuid($<))[1];
#by www.yiibai.com
system "stty -echo";
print "Password: ";
chomp($word = <STDIN>);
print "\n";
system "stty echo";
if (crypt($word, $pwd) ne $pwd) {
die "Sorry wrong password\n";
} else {
print "ok, correct password\n";
} |
|