用于检查UNIX密码的Python函数
要验证UNIX密码,我们应该使用crypt模块。它具有crypt(3)例程。它基本上是基于改进的DES算法的单向哈希函数。
要使用crypt模块,我们应该使用导入。
import crypt
方法crypt.crypt(word,salt)
此方法有两个参数。第一个是单词,第二个是盐。这个词基本上是用户密码,在提示中给出。盐是一个随机的字符串。它用于以4096种方式之一干扰DES算法。盐仅包含大写,小写,数字值和“/”,“。”。字符。
此方法以字符串形式返回哈希密码。
范例程式码
import crypt, getpass, spwd
def check_pass():
username = input("Enter The Username: ")
password = spwd.getspnam(username).sp_pwdp
if password:
clr_text = getpass.getpass()
return crypt.crypt(clr_text, password) == password
else:
return 1
if check_pass():
print("The password matched")
else:
print("The password does not match")输出结果
(具有root级权限运行此程序)
$ sudo python3 example.py Enter The Username: unix_user Password: The password matched
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿