Hashlib simple encryption and hashlib Encryption

Source: Internet
Author: User

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

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.