linux新密码与老密码不能重复,Linux如何知道新密码与前一个密码相似?

至少在我的Ubuntu中,“太相似”消息出来了 时间:“ ...超过一半的字符是不同的字符...。”(有关详细信息,请参见下文)。 感谢PAM的支持,正如@slhck答案中明确说明的那样。

对于不使用PAM的其他平台,在以下情况下会显示“过于相似”消息:“ ...超过一半的字符是不同的字符...。”(请参见下文以了解详细信息)

要自己进一步检查该语句,可以检查源代码。这是怎么回事。

passwd软件包中包含“ passwd”程序:

verzulli@iMac:~$ which passwd

/usr/bin/passwd

verzulli@iMac:~$ dpkg -S /usr/bin/passwd

passwd: /usr/bin/passwd

在处理开源技术时,我们可以不受限制地访问源代码。获得它很简单:

verzulli@iMac:/usr/local/src/passwd$ apt-get source passwd

之后,很容易找到相关的代码片段:

verzulli@iMac:/usr/local/src/passwd$ grep -i -r 'too similar' .

[...]

./shadow-4.1.5.1/NEWS:- new password is not "too similar" if it is long enough

./shadow-4.1.5.1/libmisc/obscure.c: msg = _("too similar");

快速检查一下“ obscure.c”就可以了(我只剪切并粘贴了相关的代码):

static const char *password_check (

const char *old,

const char *new,

const struct passwd *pwdp)

{

const char *msg = NULL;

char *oldmono, *newmono, *wrapped;

if (strcmp (new, old) == 0) {

return _("no change");

}

[...]

if (palindrome (oldmono, newmono)) {

msg = _("a palindrome");

} else if (strcmp (oldmono, newmono) == 0) {

msg = _("case changes only");

} else if (similar (oldmono, newmono)) {

msg = _("too similar");

} else if (simple (old, new)) {

msg = _("too simple");

} else if (strstr (wrapped, newmono) != NULL) {

msg = _("rotated");

} else {

}

[...]

return msg;

}

因此,现在,我们知道有一个“相似”功能,该功能基于旧的和新的检查两者是否相似。这是代码段:

/*

* more than half of the characters are different ones.

*/

static bool similar (const char *old, const char *new)

{

int i, j;

/*

* XXX - sometimes this fails when changing from a simple password

* to a really long one (MD5). For now, I just return success if

* the new password is long enough. Please feel free to suggest

* something better... --marekm

*/

if (strlen (new) >= 8) {

return false;

}

for (i = j = 0; ('\0' != new[i]) && ('\0' != old[i]); i++) {

if (strchr (new, old[i]) != NULL) {

j++;

}

}

if (i >= j * 2) {

return false;

}

return true;

}

我还没有审查过C代码。我限制了我对函数定义之前的注释的信任:-)

在“ obscure.c”文件中定义了PAM和NON-PAM感知平台之间的区别,其结构如下:

#include

#ifndef USE_PAM

[...lots of things, including all the above...]

#else /* !USE_PAM */

extern int errno; /* warning: ANSI C forbids an empty source file */

#endif /* !USE_PAM */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值