Chinaunix首页 | 论坛 | 博客
  • 博客访问: 865802
  • 博文数量: 66
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 2071
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-04 15:22
个人简介

从事IT相关工作近10年,获得《网络规划师》《信息系统项目管理师》《系统分析师》、Cisco等认证,对网络和操作系统有较深理解,对认证计费系统和虚拟化技术有深入研究。

文章分类

全部博文(66)

文章存档

2019年(4)

2018年(1)

2015年(2)

2014年(16)

2013年(43)

分类: LINUX

2013-09-13 13:03:02

可以直接在添加用户的时候把-s指定为/usr/bin/passwd,这样让用户想修改密码只需要用自己的原密码登陆,登陆后只能修改密码.
可以满足你既需要原密码验证,又可以改密码的要求,还不用什么加密操作。 

这个是在sudo系统上做的一些操作:

  1. #校验OS用户密码
  2. check_os_user()
  3. {
  4.     su - $LOGNAME -c 2>/dev/null
  5.     if [ $? == 0 ]
  6.     then
  7.       echo "密码正确,程序继续进行"
  8.     else
  9.       echo "密码错误,不能进行批处理操作"
  10.       exit 0
  11.     fi

openwrt 中设置密码为空 -d 参数
Usage: passwd [OPTIONS] [USER]

Change USER's password (default: current user)

-a ALG Encryption method
-d Set password to ''
-l Lock (disable) account
-u Unlock (enable) account

passwd root -d  无论后面任何参数都是去掉用户的密码,完全删除掉密码,这样会导致远程无法访问

shadow中的加密算法问题
root:$1$X8wbbOne$4P9pf6gH9CQk8FzO0TEhb1:15957:0:99999:7:::
现在只看加密的密码部分:$1$X8wbbOne$4P9pf6gH9CQk8FzO0TEhb1:15957
$ID $salt $encrypted password

ID  | Method
1   | MD5
2a | Blowfish (not in mainline glibc; added in some | Linux distributions)
5   | SHA-256 (since glibc 2.7)
6   | SHA-512 (since glibc 2.7)
MD5        | 22 characters
SHA-256 | 43 characters
SHA-512 | 86 characters
function action_passwd()
        local p1 = luci.http.formvalue("pwd1")
        local p2 = luci.http.formvalue("pwd2")
        local stat = nil

        if p1 or p2 then
                if p1 == p2 then
                        stat = luci.sys.user.setpasswd("root", p1)
                else
                        stat = 10
                end
        end

        luci.template.render("admin_system/passwd", {stat=stat})
end

"(echo '" .. password .. "'; sleep 1; echo '" .. password .. "') | " ..     "passwd '" .. username .. "' >/dev/null 2>&1"  

太有才了,这样的确可以修改密码
(echo '900424'; sleep 1;echo '900424';) | passwd root > /dev/null 2>&1

cat /etc/shadow | awk -F ':' '/root/{print $2}'

--- Retrieve the current user password hash.
-- @param username      String containing the username to retrieve the password for
-- @return                      String containing the hash or nil if no password is set.
-- @return                      Password database entry
function user.getpasswd(username)
        local pwe = nixio.getsp and nixio.getsp(username) or nixio.getpw(username)
        local pwh = pwe and (pwe.pwdp or pwe.passwd)
        if not pwh or #pwh < 1 or pwh == "!" or pwh == "x" then
                return nil, pwe
        else
                return pwh, pwe
        end
end

--- Test whether given string matches the password of a given system user.
-- @param username      String containing the Unix user name
-- @param pass          String containing the password to compare
-- @return                      Boolean indicating wheather the passwords are equal
function user.checkpasswd(username, pass)
        local pwh, pwe = user.getpasswd(username)
        if pwe then
                return (pwh == nil or nixio.crypt(pass, pwh) == pwh)
        end
        return false
end


使用luci修改检验密码的操作如下
getuser (uid) Retrieve user informations for given uid.
checkpasswd (username, pass) Test whether given string matches the password of a given system user.
getpasswd (username) Retrieve the current user password hash.
setpasswd (username, password) Change the password of given user.

  1. #!/usr/bin/lua
  2. require "luci.cacheloader"
  3. require "luci.sgi.cgi"
  4. --luci.dispatcher.indexcache = "/tmp/luci-indexcache"
  5. --luci.sgi.cgi.run()
  6.  
  7.  
  8. local user = luci.sys.user;
  9.  
  10. rs = user.getpasswd('root');
  11. print(rs)
  12.  
  13. rs = user.checkpasswd('root','123456');
  14.  
  15. if (rs == true) then
  16.         print 'right'
  17. else
  18.         print 'wrong'
  19. end
  20.  
  21. passwd = '123456'
  22. rs = user.setpasswd('root',passwd)






阅读(6833) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~