Package: password-library
passwordlib-pyutility library to verify, hash, compare and more for passwordsInstallationJust runpip install password-libraryExample usagepasswordlib offers an easy interface to create password-hashesfrompasswordlibimportutilaspwutilhashed=pwutil.hash_password("my_secret")print(pwutil.compare_password("your_secret",hashed))# Falseprint(pwutil.compare_password("my_secret",hashed))# Trueprint(pwutil.extract_algorythm(hashed))# sha256print(pwutil.extract_iterations(hashed))# 100_000print(pwutil.extract_salt(hashed))# b'...'print(pwutil.extract_hashed(hashed))# b'...'you can also configure the algorithms or number of iterationsfrompasswordlibimportutilaspwutil,configaspwconfig# either globallypwconfig.DEFAULT_ALGORITHM="md5"pwconfig.DEFAULT_ITERATIONS=1_000_000pwconfig.DEFAULT_SALT_LENGTH=64# or per instancepwutil.hash_password(password='password',algorithm="md5",iterations=1_000_000,salt_length=64,)it also offers thePasswordAttributeclass to automatically hash attributes on objectsfrompasswordlib.attrimportPasswordAttributeclassUser:name:strpassword=PasswordAttribute()user=User()print(user.password)# Noneuser.password="secret"print(user.password)# b'\x06sha256\x00\x01\x86\xa0\x00 \x07\xcfg\x0ec\xa6D\xea\xae\x03S\xa1\xfcz\xaew\x02\x8b\xf1\xe5\xaf\x83n&\x87'\xcdRi!\xd9\xe7\x00@qV\xd3\x81\x113:*"\x05\xba\x12Xb\x04\xeb\x08Sn\x08Z\x9f\x89\xa50~\xa0\xb4\xbd.\xc6\x18"\xf9l\xeds\xbc\xc2B\xa7\xef\xa1\x8a\x7f3\xc1u\x17d\xce\xf2\x98+l\x86\xb7\x1c\xb4\xf0\x07t8\xc9'you can also check if a password is commonly usedfrompasswordlib.commonly_usedimportis_commonly_usedprint(is_commonly_used("password"))# Trueprint(is_commonly_used("123456"))# Trueprint(is_commonly_used("matrix"))# Trueprint(is_commonly_used("password-library"))# Falseprint(is_commonly_used("TifnedjothUj"))# Falseand be able to validate a password against different criteria
to ensure a password is safe.frompasswordlib.analyzerimportAnalyzer# may not seem safe at first, but think:# 9 digits,lowercase and symbols, not commonly used and no repeating charactersresult=Analyzer("my_secret")print(result.is_secure)# Trueprint(result.is_highly_secure)# Falseprint(result.score)# 5print(result.contains_lowercase)# Trueprint(result.contains_uppercase)# Falseprint(result.contains_digits)# Falseprint(result.contains_symbols)# Trueprint(result.length)# 9print(result.max_consecutive_character)# 1print(result.is_commonly_used)# False# you can do such a check here:number_of_security_features=sum((result.contains_lowercase,result.contains_uppercase,result.contains_digits,result.contains_symbols,result.length>=8,result.charset_length>(result.length//2)))ifnumber_of_security_features<5orresult.is_commonly_used:raisePasswordTooWeakError(result.password)# here are more examples for your=Analyzer("password")print(r.score,r.is_secure,r.is_highly_secure)# 0 False Falser=Analyzer("123456")print(r.score,r.is_secure,r.is_highly_secure)# 0 False Falser=Analyzer("matrix")print(r.score,r.is_secure,r.is_highly_secure)# 0 False Falser=Analyzer("password-library")print(r.score,r.is_secure,r.is_highly_secure)# 7 True Falser=Analyzer("TifnedjothUj")print(r.score,r.is_secure,r.is_highly_secure)# 6 True Falser=Analyzer("passwoooooooooooooord")print(r.score,r.is_secure,r.is_highly_secure)# 1 False FalseRoadmappasswordlibpasswordlib.utildef hashingdef comparingdef dumpingdef loadingpasswordlib.attrclass PasswordAttributepasswordlib.commonly_useddef is_common_passwordpasswordlib.Analyzerclass Analyzerpasswordlib.validatorclass PasswordValidatorpasswordlib.validator.rulesDocumentation