Hashlib simple encryption and hashlib Encryption
Import hashlibdef md5 (arg): # This is the encryption function md5_pwd = hashlib. md5 (bytes ('meac', encoding = 'utf-8') md5_pwd.update (bytes (arg, encoding = 'utf-8') return md5_pwd.hexdigest () # Return encrypted data def log (user, pwd): try: with open ('login', 'R', encoding = 'utf-8') as f: for line in f: u, p = line. strip (). split ('|') if u = user and p = md5 (pwd ): # verify that the user name and encrypted password are the same as those saved previously. return True return False handle T: return Falsedef register (user, Pwd): # Write the user name and encrypted password into the file during registration and save it with open ('login', 'A', encoding = 'utf-8 ') as f: temp = user + '|' + md5 (pwd) f. write (temp) while 1: m = input ('enter the serial number: 1. Indicates logon, 2. indicates Registration ') if m = '1': user = input ('enter Logon account:') pasw = input ('enter Logon account password :') if log (user, pasw) = False: print ('logon failed, system launch ') break else: print ('logon successfully') elif m = '2 ': user = input ('Enter the registered account: ') pasw = input ('Enter the registered account password:') register (user, pasw) print ('registered successfully') else: print ('feature does not exist') break