26 lines
615 B
Python
26 lines
615 B
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
import crypt, crack, popen2, random
|
||
|
|
||
|
def generate_password():
|
||
|
(o, i, e) = popen2.popen3("apg -n 1 -m 8 -x 12 -a 0")
|
||
|
|
||
|
return "".join(o.readlines()).strip()
|
||
|
|
||
|
def check_password(password):
|
||
|
try:
|
||
|
return crack.VeryFascistCheck(password)
|
||
|
except ValueError, ve:
|
||
|
print "Weak password:", ve
|
||
|
return None
|
||
|
|
||
|
def md5_crypt_password(password):
|
||
|
salt = "".join([chr(letter) for letter in random.sample(range(ord('a'), ord('z')), 8)])
|
||
|
|
||
|
return crypt.crypt(password, '$1$' + salt)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
print check_password("test")
|
||
|
print generate_password()
|
||
|
print md5_crypt_password("test")
|