4 # useful function(s) for module crypt
8 from __future__ import print_function
12 saltchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcedfghijklmnopqrstuvwxyz0123456789./"
13 len_salt = len(saltchars)
17 There are some difference among modern unicies. BSD/OS, for example,
18 uses MD5 hash, and ignores salt completely. FreeBSD uses 3 different
19 versions of crypt() - with standard salt, with extended 9-byte salt,
20 and MD5 (again, ignoring salt at all).
21 This function generates salt for standard "Broken DES"-based crypt().
23 r1 = random.randint(0, len_salt-1)
24 r2 = random.randint(0, len_salt-1)
25 return "%s%s" % (saltchars[r1], saltchars[r2])
29 passwd = raw_input("Enter password: ")
31 encrypted = crypt.crypt(passwd, salt)
33 pwd_file = open("test.pwd", 'w')
34 pwd_file.write("%s:%s" % ("user", encrypted))
36 print("Password file written")
39 pwd_file = open("test.pwd", 'r')
40 username, encrypted = string.split(pwd_file.readline()[:-1], ':')
43 if crypt.crypt(encrypted, encrypted):
44 print("Password verified Ok")
48 if __name__ == "__main__":