python模块使用/etc/shadow文件验证linux用户的凭据
shadow-auth的Python项目详细描述
这是一个python模块,用于使用/etc/shadow文件验证linux用户的凭据。
请查看有关如何安装和使用shadow_auth的完整文档:
如何使用Linux影子身份验证:
importshadow_authifshadow_auth.validate_with_password("username","1234"):# What to do if the user is validpassifshadow_auth.validate_with_hash("username","$1$TrOIigLp$FJg1nUqEQPt4OerLOWzr/1"):# What to do if the user is validpass#Get the algorithm and Salt for a User password_info=shadow_auth.get_password_info("username")# password_info = {# "algorithm" = "1",# "salt" = "TrOIigLp"# }#Generate an MD5 hashnew_md5_hash=shadow_auth.generate_openssl_hash(algorithm=shadow_auth.Algorithm.MD5,salt="TrOIigLp",text="abcd12345",)# new_md5_hash = "$1$TrOIigLp$FJg1nUqEQPt4OerLOWzr/1"#Generate an SHA-256 hashnew_sha_256_hash=shadow_auth.generate_openssl_hash(algorithm=shadow_auth.Algorithm.MD5,salt="TrOIigLp",text="abcd12345",)# new_sha_256_hash = "$5$TrOIigLp$6usEDvu0NgyuQ/IqQyvSBoP0x2RiNOz5izrMViHwXv2"#Generate an SHA-512 hashnew_sha_512_hash=shadow_auth.generate_openssl_hash(algorithm=shadow_auth.Algorithm.MD5,salt="TrOIigLp",text="abcd12345",)# new_sha_512_hash = "$6$TrOIigLp$IU0KwZfzVkuLLy/9vMFH1RgOmqE3LAGk0K9/15WOGStkeaN2IWYkY0jzCWHMUcSnnewnt9bOUwD2vStgko79v/"