4 # useful function(s) for module crypt
6 # Author: Oleg Broytman <phd@phd.pp.ru>
7 # Copyright (C) 1998-1999 PhiloSoft Design
14 saltchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcedfghijklmnopqrstuvwxyz0123456789./"
15 len_salt = len(saltchars)
19 There are some difference among modern unicies. BSD/OS, for example,
20 uses MD5 hash, and ignores salt completely. FreeBSD uses 3 different
21 versions of crypt() - with standard salt, with extended 9-byte salt,
22 and MD5 (again, ignoring salt at all).
23 This function generates salt for standard "Broken DES"-based crypt().
25 r1 = random.randint(0, len_salt-1)
26 r2 = random.randint(0, len_salt-1)
27 return "%s%s" % (saltchars[r1], saltchars[r2])
31 passwd = raw_input("Enter password: ")
33 encrypted = crypt.crypt(passwd, salt)
35 pwd_file = open("test.pwd", 'w')
36 pwd_file.write("%s:%s" % ("user", encrypted))
38 print "Password file written"
41 pwd_file = open("test.pwd", 'r')
42 username, encrypted = string.split(pwd_file.readline()[:-1], ':')
45 if crypt.crypt(encrypted, encrypted):
46 print "Password verified Ok"
50 if __name__ == "__main__":