您的位置:首页 > 运维架构 > Linux

LINUX下 如何验证系统用户名和密码是否正确。

2008-05-06 20:34 2659 查看
原贴:http://blog.chinaunix.net/u/14673/showart_289691.html

LINUX下 如何验证系统用户名和密码是否正确。
这个问题想了好久。。好像shell下面没有直接调用的东西,来让我做用户名和密码的验证。于是想到了自己写一个。

原理:用ssh,连接本地,然后判断用户名密码是否正确。
代码:(需要expect支持,另:expect 需要tcl支持)

#!/root/download/expect-5.30/expect -f
#usage:shell_test name password

if {$argc!=2}/
{
send_user "Usage:shell_test name password"
exit 1
}
set name [lindex $argv 0]
set password [lindex $argv 1]
set isSend 0
spawn ssh -t "${name}@localhost"
expect /
{
"* (yes/no)*" {send "yes/r"} /
"* password:*" /
{
send "${password}/r"
set isSend 1
} /
default {send_user "error"}
}
if {$isSend==0}/
{
expect "* password:*" {send "${password}/r"} /
default {send_user "error"}
}
expect /
{
"Permission denied" {send_user "Not allowed"} /
"*~]" /
{
send_user "OK"
send "exit/r"
} /
default /
{
send_user "error"
exit 1
}
}
exit 0

有没有高人给点建议,应该怎么认证啊.

TAG linux expect authentication
发表于: 2007-04-30,修改于: 2007-04-30 14:05,已浏览241次,有评论0条 推荐 投诉
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: