Registration process, the user name and password stored in the database

user table
table column id username password error_count
registered program, which exists in the database the account password, to deposit ciphertext
1. Enter input (username, password, cpwd)

2. select statement, the presence of absence of the user is determined

3. does not exist on the implementation of the insert statement
4.password bit encryption

import pymysql,hashlib

def op_mysql(sql):
    db_info = {'user': 'xxx', 'password': 'xxxxxx',
            'host': '127.0.0.1', 'db': 'xxx', 'port': 3306, 'charset': 'utf8',
            'the autocommit ' : True} 
    Conn = pymysql.connect (** db_info)   # establish a connection 
    CUR = conn.cursor (pymysql.cursors.DictCursor)   # cursor 
    cur.execute (sql)   # execute sql statement, INSERT, Update, Delete 
    Result = cur.fetchall () 
    cur.close () 
    conn.Close () 
    return Result 

for I in Range (. 3 ): 
    username = iNPUT ( ' enter username: ' ) .strip () 
    password = iNPUT ( ' enter password: ' ) .strip () 
    cpasswdINPUT = ( ' reconfirm the password: ' ) .strip () 
    SQL1 = ' SELECT * WHERE from User username = "% S"; ' % (username)
     IF username == ''  or password == ''  or cpasswd = = '' :
         Print ( ' user name or password can not be empty! ' )
     elif password =! cpasswd:
         Print ( ' passwords do not match the two entries, re-register ' )
     elif   op_mysql (SQL1):
         Print ( 'Username already exists, please re-register ')
     The else : 
        ha_pwd = hashlib.md5 (password.encode ()) 
        md5_pwd = ha_pwd.hexdigest () 
        SQL2 = ' INSERT INTO User (username, password, ERROR_COUNT) values ( "% S", "% S", 0); ' % (username, md5_pwd) 
        op_mysql (SQL2) 
        Print ( ' !% S, Congratulations on successfully registered ' % username)
         BREAK 
the else :
     Print ( ' registration failed, please try again later! ' )

 

Guess you like

Origin www.cnblogs.com/cathyg/p/11780014.html