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