Python Backend Registration Login Verification Applet

Source: Internet
Author: User

Altogether four documents

The function is to register the account, write to the MySQL database user (id,name,password,createtime) table, the password field is encrypted with MD5 password, and implement password Authentication login.

First on:

1. Registration

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/9F/7D/wKioL1mdcZ6DHbizAAA8joFpRFw308.png-wh_500x0-wm_ 3-wmp_4-s_129113035.png "title=" Register.png "alt=" Wkiol1mdcz6dhbizaaa8jofprfw308.png-wh_50 "/>

2. Login Verification

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/00/CD/wKiom1mdcdTC9hvIAABNzxhSMXo605.png-wh_500x0-wm_ 3-wmp_4-s_2046523173.png "title=" Login.png "alt=" Wkiom1mdcdtc9hviaabnzxhsmxo605.png-wh_50 "/>

3. Database

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/9F/7D/wKioL1mdcg-TpaoDAABE0gygpE0863.png-wh_500x0-wm_ 3-wmp_4-s_1971020331.png "title=" Shuju.png "alt=" Wkiol1mdcg-tpaodaabe0gygpe0863.png-wh_50 "/>

Note: The data in 24,25 is a cryptographic string that encrypts only the user input, 18,19,26,27 is a combination of the three field contents of the encrypted name,password,createtime, and 20 to 23 is not encrypted.


1. configuration file config.py

#mysql info for host,user,passwordhostname= "localhost" port= "3306" user= "Login" password= "123456" database= "Login"

2. Database Connection File connect.py

#!/usr/local/bin/python3import pymysqlfrom Config import *conn=pymysql.connect (host=hostname,user=user,passwd= Password,db=database) Cursor=conn.cursor ()

3. Registration Document REGISTER.PY

#!/usr/local/bin/python3from connect import *import timeimport hashlibdef md5 ( ARG):     md5_pwd = hashlib.md5 (bytes (' Abd ', encoding= ' Utf-8 '))      md5_pwd.update (bytes (arg,encoding= ' utf-8 '))     return md5_pwd.hexdigest () def  register (): Try:while true:name=input ("Enter your Name:"). Strip () Cursor.execute ("Select count (*)   from user where name=%s ",  name) Count=cursor.fetchone () [0]length=len (name) if count  == 1:print ("User name already exists!") ") continueelif length<6:print (" User name is at least 6 characters! ") continueelif length>15:print (" User name up to 15 characters!) ") Continueelif count == 0 and length>=6 and length=<15:password=input ("Enter your password:"). Strip () Time=int (Time.time ()) String=name+password+str (Time) passwd=md5 (string) cursor.execute ("Insert  into user (name,passwd,createtime)  values (%s,%s,%s) ", (Name,passwd,time)) Breakexcept: Conn.rollback() Else:conn.commit () Conn.close () register () 

4. Login Verification File login.py

#!/usr/local/bin/python3from connect import *import hashlibdef md5 (ARG):     md5_pwd = hashlib.md5 (bytes (' Abd ', encoding= ' Utf-8 '))     md5_ Pwd.update (bytes (arg,encoding= ' utf-8 '))     return md5_pwd.hexdigest () Def login () : Name=input ("Enter your Name:"). Strip () Cursor.execute ("Select count (*)  from user where name=%s ", name) Count=cursor.fetchone () [0]print (count) if count == 1:i=0while  (i<3): Cursor.execute ("select createtime from user where name=%s", name) Time=cursor.fetchone ( [0]password=input ("Enter your password:"). Strip () String=name+password+str (Time) passwd=md5 (string) cursor.execute ("Select  password from user where name=%s ", name) Password_db=cursor.fetchone () [0]i=i+1j=3-iif  passwd == password_db:print ("Login Successful! Welcome to%s. " % name) Conn.close () breakelif passwd != password_db:print (" Password error, please re-enter! Print ("You can also enter%s times!") " % j" Continuebreakelif count == 0:print ("Your account does not exist!") ") Login ()

This article is from the "Start Again" blog, please be sure to keep this source http://4708705.blog.51cto.com/4698705/1958766

Python Backend Registration Login Verification Applet

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.