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])
31 except NameError: # Python 3
34 passwd = raw_input("Enter password: ")
36 encrypted = crypt.crypt(passwd, salt)
38 pwd_file = open("test.pwd", 'w')
39 pwd_file.write("%s:%s" % ("user", encrypted))
41 print("Password file written")
43 pwd_file = open("test.pwd", 'r')
44 username, encrypted = pwd_file.readline()[:-1].split(':')
47 if crypt.crypt(encrypted, encrypted):
48 print("Password verified Ok")
52 if __name__ == "__main__":