文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>LINUX下 如何验证系统用户名和密码是否正确。

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

时间:2007-04-30  来源:Givemefive

这个问题想了好久。。好像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

 

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

相关阅读 更多 +
排行榜 更多 +
星宇驾考

星宇驾考

学习教育 下载
我快递

我快递

音乐节奏 下载
减速射手

减速射手

飞行射击 下载