如何要求用户的密码必须符合一定的复杂度

2023-11-02

如何要求用户的密码必须符合一定的复杂度
 
我们在使用 linux 系统 设置密码的时候,经常遇到这样的问题,系统提示:您的密码太简单,或者您的密码是字典的一部分。那么系统是如何实现对用户的密码的复杂度的检查的呢?
系统对密码的控制是有两部分(我知道的)组成:
1 cracklib
2 login.defs

声明:login.defs主要是控制密码的有效期。对密码进行时间管理。此处不细谈
login.defs   --shadow password suite configuration


pam_cracklib.so 才是控制密码复杂度的关键 文件
redhat公司专门 开发了cracklib这个 安装包来判断密码的复杂度
可以rpm -ql cracklib查看
密码的复杂度的判断是通过pam 模块控制来实现的,具体的模块是pam_cracklibpam_cracklib 的参数介绍:

debug

    This option makes the module write information to syslog(3) indicating the behavior of the module (this option does not write password information to the log file).
type=XXX
    The default action is for the module to use the following prompts when requesting passwords: "New UNIX password: " and "Retype UNIX password: ". The default word UNIX can be replaced with this option.
retry=N
    Prompt user at most N times before returning with error. The default is 1
difok=N
    This argument will change the default of 5 for the number of characters in the new password that must not be present in the old password. In addition, if 1/2 of the characters in the new password are different then the new password will be accepted anyway.
difignore=N
    How many characters should the password have before difok will be ignored. The default is 23.
minlen=N
    The minimum acceptable size for the new password (plus one if credits are not disabled which is the default). In addition to the number of characters in the new password, credit (of +1 in length) is given for each different kind of character (other, upper, lower and digit). The default for this parameter is 9 which is good for a old style UNIX password all of the same type of character but may be too low to exploit the added security of a md5 system. Note that there is a pair of length limits in Cracklib itself, a "way too short" limit of 4 which is hard coded in and a defined limit (6) that will be checked without reference to minlen. If you want to allow passwords as short as 5 characters you should not use this module.
dcredit=N
    (N >= 0) This is the maximum credit for having digits in the new password. If you have less than or N digits, each digit will count +1 towards meeting the current minlen value. The default for dcredit is 1 which is the recommended value for minlen less than 10.

    (N < 0) This is the minimum number of digits that must be met for a new password.
ucredit=N
    (N >= 0) This is the maximum credit for having upper case letters in the new password. If you have less than or N upper case letters each letter will count +1 towards meeting the current minlen value. The default for ucredit is 1 which is the recommended value for minlen less than 10.

    (N > 0) This is the minimum number of upper case letters that must be met for a new password.
lcredit=N
    (N >= 0) This is the maximum credit for having lower case letters in the new password. If you have less than or N lower case letters, each letter will count +1 towards meeting the current minlen value. The default for lcredit is 1 which is the recommended value for minlen less than 10.

    (N < 0) This is the minimum number of lower case letters that must be met for a new password.
ocredit=N
    (N >= 0) This is the maximum credit for having other characters in the new password. If you have less than or N other characters, each character will count +1 towards meeting the current minlen value. The default for ocredit is 1 which is the recommended value for minlen less than 10.

    (N < 0) This is the minimum number of other characters that must be met for a new password.
use_authtok
    This argument is used to force the module to not prompt the user for a new password but use the one provided by the previously stacked password module.
dictpath=/path/to/dict
    Path to the cracklib dictionaries.

  
dictpath=/path/to/dict //注:密码字典,这个是验证用户的密码是否是字典一部分的关键。
Path to the cracklib dictionaries.

cracklib密码强度检测过程

首先检查密码是否是字典的一部分,如果不是,则进行下面的检查

密码强度检测过程

These checks are:

Palindrome
    Is the new password a palindrome of the old one?

新密码是否旧密码的回文

Case Change Only
    Is the new password the the old one with only a change of case?
新密码是否只是就密码改变了大小写

Similar
    Is the new password too much like the old one?
    新密码是否和旧密码很相似
    This is primarily controlled by one argument, difok which is a number of characters that if different between the old and new are enough to accept the new password, this defaults to 10 or 1/2 the size of the new password whichever is smaller.

    To avoid the lockup associated with trying to change a long and complicated password, difignore is available. This argument can be used to specify the minimum length a new password needs to be before the difok value is ignored. The default value for difignore is 23.
Simple
    Is the new password too small?
    新密码是否太短

    This is controlled by 5 arguments minlen, dcredit, ucredit, lcredit, and ocredit. See the section on the arguments for the details of how these work and there defaults.
Rotated
    Is the new password a rotated version of the old password?
        新密码的字符是否是旧密码字符的一个循环
    例如旧密码:123
       新密码:231
        
Already used
    Was the password used in the past?
    这个密码以前是否使用过
    Previously used passwords are to be found in /etc/security/opasswd.


那么系统是如何实现这个控制的呢?
在系统的配置文件/etc/pam.d/system-auth 中有这样一行
password requisite     pam_cracklib.so try_first_pass retry=3

我们可以根据pam_cracklib的参数这样配置这个pam模块来达到我们想要的目的
password required /lib/security/pam_cracklib.so retry=3 type= minlen=8 difok=3 dictpath=/path/to/dict



参考资料
http://linux.die.net/man/5/login.defs
http://linux.die.net/man/8/pam_cracklib
http://kbase.redhat.com/faq/FAQ_80_4045.shtm

转载于:https://blog.51cto.com/uplook/353770

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何要求用户的密码必须符合一定的复杂度 的相关文章

  • 如何使用 JavaScript 或 jQuery 克隆 HTML 元素的样式对象?

    我正在尝试克隆元素的样式对象 这应该允许我在更改后重置所述元素的样式 例如 el style left 50px curr style left 50px Modify the elements style The cloned style
  • 两个类可以使用 C++ 互相查看吗?

    所以我有一个 A 类 我想在其中调用一些 B 类函数 所以我包括 b h 但是 在 B 类中 我想调用 A 类函数 如果我包含 a h 它最终会陷入无限循环 对吗 我能做什么呢 仅将成员函数声明放在头文件 h 中 并将成员函数定义放在实现文
  • 空指针与 int 等价

    Bjarne 在 C 编程语言 中写道 空指针与整数零不同 但 0 可以用作空指针的指针初始值设定项 这是否意味着 void voidPointer 0 int zero 0 int castPointer reinterpret cast
  • 使用 next.js 进行服务器端渲染与传统 SSR

    我非常习惯 SSR 意味着页面得到完全刷新并从服务器接收完整 HTML 的方法 其中根据后端堆栈使用 razor pub other 进行渲染 因此 每次用户单击导航链接时 它只会向服务器发送请求 整个页面将刷新 接收新的 HTML 这就是
  • 如何在 Android 中使用 C# 生成的 RSA 公钥?

    我想在无法假定 HTTPS 可用的情况下确保 Android 应用程序和 C ASP NET 服务器之间的消息隐私 我想使用 RSA 来加密 Android 设备首次联系服务器时传输的对称密钥 RSA密钥对已在服务器上生成 私钥保存在服务器
  • 在 Pandas DataFrame Python 中添加新列[重复]

    这个问题在这里已经有答案了 例如 我在 Pandas 中有数据框 Col1 Col2 A 1 B 2 C 3 现在 如果我想再添加一个名为 Col3 的列 并且该值基于 Col2 式中 如果Col2 gt 1 则Col3为0 否则为1 所以
  • 使用 Enzyme 测试 `React.createRef` api

    我想测试下面的类 它使用React createRef api 不过 快速搜索并没有发现任何这样做的例子 有人成功过吗 我该如何嘲笑裁判 理想情况下我想使用shallow class Main extends React Component
  • 对输入求 Keras 模型的导数返回全零

    所以我有一个 Keras 模型 我想将模型的梯度应用于其输入 这就是我所做的 import tensorflow as tf from keras models import Sequential from keras layers imp
  • 有没有办法让 doxygen 自动处理未记录的 C 代码?

    通常它会忽略未记录的 C 文件 但我想测试 Callgraph 功能 例如 您知道在不更改 C 文件的情况下解决此问题的方法吗 设置变量EXTRACT ALL YES在你的 Doxyfile 中
  • 如何使用google colab在jupyter笔记本中显示GIF?

    我正在使用 google colab 想嵌入一个 gif 有谁知道如何做到这一点 我正在使用下面的代码 它并没有在笔记本中为 gif 制作动画 我希望笔记本是交互式的 这样人们就可以看到代码的动画效果 而无需运行它 我发现很多方法在 Goo
  • C++ 中的 include 和 using 命名空间

    用于使用cout 我需要指定两者 include
  • 滚动顶部不符合预期

    Note 由于上次忘记奖励而重新开放赏金 A Woff 大师已经给出答案 我想在用户展开某一行时到达该行 这样当最后一个可见行展开时 用户不必向下滚动即可查看内容 I used example tbody on click td green
  • 在 Python 类中动态定义实例字段

    我是 Python 新手 主要从事 Java 编程 我目前正在思考Python中的类是如何实例化的 我明白那个 init 就像Java中的构造函数 然而 有时 python 类没有 init 方法 在这种情况下我假设有一个默认构造函数 就像
  • 当文件流没有新数据时如何防止fgets阻塞

    我有一个popen 执行的函数tail f sometextfile 只要文件流中有数据显然我就可以通过fgets 现在 如果没有新数据来自尾部 fgets 挂起 我试过ferror and feof 无济于事 我怎样才能确定fgets 当
  • 如何从 json 文件创建模型? (ExtJS)

    这是我想使用 json 文件创建的模型 Ext define Users extend Ext data Model fields name user id type int name user name type string 为了根据服
  • Python:元类属性有时会覆盖类属性?

    下面代码的结果让我感到困惑 class MyClass type property def a self return 1 class MyObject object metaclass MyClass a 2 print MyObject
  • 如何通过索引访问 JSON 对象中的字段

    我知道这不是最好的方法 但我别无选择 我必须通过索引访问 JSONObject 中的项目 访问对象的标准方法是只写this objectName or this objectName 我还找到了一种获取 json 对象内所有字段的方法 fo
  • 测量窗口偏移

    有没有一种方法可以测量 jQuery 中窗口的偏移量 以便我可以比较 固定 元素和相对定位元素的位置 我需要能够知道窗口滚动了多远 以便我可以使用该图来计算固定元素的高度 相对于视口顶部 和相对对象的高度 相对于顶部 之间的差异文件的内容
  • 从 mvc 控制器使用 Web api 控制器操作

    我有两个控制器 一个mvc控制器和一个api控制器 它们都在同一个项目中 HomeController Controller DataController ApiController 如果我想从 HomeController 中使用 Dat
  • 使用 WGL 创建现代 OpenGL 上下文?

    我正在尝试使用 Windows 函数创建 OpenGL 上下文 现代版本 基本上代码就是 创建窗口类 注册班级 创建一个窗口 choose PIXELFORMATDESCRIPTOR并设置它 创建旧版 OpenGL 上下文 使上下文成为当前

随机推荐

  • 刷题之旅第33站,CTFshow web12

    感谢ctf show平台提供题目 F12查看一下源代码 得到了提示 既然提示了cmd 那么可能后端代码中存在 eval 或者exec 等可以执行命令的代码 尝试提交 我们看到了php的配置信息 cmd phpinfo 使用glob通配符命令
  • C++笔记三(封装、静态、const、友元)

    1 C 面向对象特性 1 1C 面向对象的三大特性为 封装 继承 多态 万物皆对象 2 封装 2 1 封装的意义 其一 将属性和行为作为一个整体 表现生活中的事物 创建类别忘了 后有个 其实可以理解为类与结构体类似 类中的属性与行为统一称为
  • condition_variable用法

    参考文章 https blog csdn net princeteng article details 103945610添加链接描述 condition variable con 有两种用法 用法一 con wait lck return
  • UMC云管理平台下ESB产品升级说明

    随着近些年各种层出不穷的技术以及企业核心需求的推动 IT行业的发展势必会倒逼公司旗下产品的升级迭代 同时在产品由旧变新的升级过程中也有很多注意要点 由于公司产品大多以整合方案的形式部署到环境上 所以升级部署是否可快速简便尤为重要 产品升级对
  • 基于redis分布式锁解决定时任务重复问题

    在看代码之前请先看优化篇 基于Redis的Setnx实现分布式锁 p f 的博客 CSDN博客 1 在启动了上加 EnableScheduling 注解 SpringBootApplication MapperScan com xpf di
  • 华为OD机试 - 字符串分割(Java )

    题目描述 给定非空字符串s 将该字符串分割成一些子串 使每个子串的ASCII码值的和均为水仙花数 1 若分割不成功 则返回0 2 若分割成功且分割结果不唯一 则返回 1 3 若分割成功且分割结果唯一 则返回分割后子串的数目 输入描述 输入字
  • 运算放大器的选择---相关参数

    1 供电电压Vs 有单电源电压 双电源电压 双电源电压尽量两个电源都接 2 输入电压范围和输出电压范围 输入电压接近供电电压时 就称为输入电压轨到轨 如图8 LM358输入电压能达到负电源轨 不能达到正电源轨 输出电压非轨到轨 3 输入偏置
  • 的技术难点_推铅球技术教学的重点与难点

    一 推铅球的技术特点 推铅球技术的变革 无论从侧向到背向 还是从背向到旋转 不外乎有以下几个趋势 一是尽量加长铅球在手中运行的距离 使铅球预先获得较大的初速度 二是尽量加长最后用力的工作距离 三是能使更多的肌肉群参与推铅球的最后用力 并为这
  • Gradle 奇技淫巧

    http blog chengyunfeng com p 833 Gradle 奇技淫巧 作者 rain 分类 奇技淫巧 移动 发布时间 2015 12 31 19 42 6 0条评论 Gradle 现在已经是 Android 开发必备的建
  • Java内存泄漏的排查总结

    一 内存溢出和内存泄露 一种通俗的说法 1 内存溢出 你申请了10个字节的空间 但是你在这个空间写入11或以上字节的数据 出现溢出 2 内存泄漏 你用new申请了一块内存 后来很长时间都不再使用了 按理应该释放 但是因为一直被某个或某些实例
  • Syntax Error while loading YAML.   did not find expected '-' indicator

    运行剧本出错 ERROR Syntax Error while loading YAML did not find expected indicator The error appears to have been in etc ansib
  • C语言-哈希查找(HASH)-详解(完整代码)

    目录 原理 实例解释 存储逻辑图 需要的知识 附加 完整代码 代码详解 执行结果 1 查找个不存在的 2 查找个存在的 原理 用一个指针数组 来存储 每个链表的头节点 的首地址 如果要从 NUM 个数中查找数据 先对 NUM 0 75 求得
  • 【c++primer第五版】第十一章习题答案

    第十一章 关联容器 练习11 1 描述map和vector的不同 解 顺序容器中的元素是 顺序 存储的 对于vector 元素在其中按顺序存储 每个元素都有唯一对应 的位置编号 所有操作都是按编号进行的 例如 获取元素 头 尾 下标 插入删
  • 继承QDialog的类弹框不阻塞

    继承QDialog的类 如myDialog 在myDialog构造函数设置模态如下 this gt setWindowModality Qt ApplicationModal 使用如下 myDialog pMyDlg new myDialo
  • MariaDB(mysql的替代品)

    原文地址 http www csdn net article 2013 04 25 2815043 lookout oracle they tem up Oracle于09年收购了Sun 其中必不可少的原因就是获得MySQL这个最热门开源D
  • 【计算机网络系列】网络层⑩:路由选择协议——外部网关协议BGP

    外部网关协议BGP 协议BGP的主要特点 在外部网关协议 或边界网关协议 BGP中 现在使用的是第4个版本BGP 4 常简写为BGP 协议BGP对互联网非常重要 前面介绍的路由选择协议RIP和OSPF 都只能在一个自治系统AS内部工作 因此
  • leetcode刷题:三数之和

    题目 分析 这是最容易想到的做法 但是有明显的问题 时间复杂度达到0 n3 并且没有去重 class Solution public vector
  • 华为OD机试 - 模拟消息队列(Python)

    题目描述 让我们来模拟一个消息队列的运作 有一个发布者和若干消费者 发布者会在给定的时刻向消息队列发送消息 若此时消息队列有消费者订阅 这个消息会被发送到订阅的消费者中优先级最高 输入中消费者按优先级升序排列 的一个 若此时没有订阅的消费者
  • asp服务器 首选精图数码稳定,架设游戏服务端选什么云服务器

    架设游戏服务端选什么 DDOS是游戏 1 网络层攻击 YNFlood ACKFlood ICMPFlood UDPFlood NTPFlood SSDPFlood DNSFlood等 2 应用层攻击 CC攻击 3 HTTP的攻击等网络攻击
  • 如何要求用户的密码必须符合一定的复杂度

    如何要求用户的密码必须符合一定的复杂度 我们在使用 linux 系统 设置密码的时候 经常遇到这样的问题 系统提示 您的密码太简单 或者您的密码是字典的一部分 那么系统是如何实现对用户的密码的复杂度的检查的呢 系统对密码的控制是有两部分 我