原贴: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条 推荐 投诉
           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐