def get_sha1_mysql(self,sql,param): #连接数据库,查询数据库sha1加密密码 mysqltest = MysqlHelper(host=self.host,user=self.user,password=self.pwd,database=self.database,port=self.port,charset=self.charset) ret = mysqltest.all(sql,param) return ret
#encodeing=utf-8 from MysqlHelper import * from hashlib import sha1 name = input('请输入用户名:') pwd = input('请输入密码') #加密 sha = sha1() sha.update(pwd.encode('utf-8')) pwd2 = sha.hexdigest print(str(pwd2)) #根据用户名查询 query = 'select passwd from users where name=%s' sqlhelper = MysqlHelper('localhost', 3306, 'pymysql', 'root', 'kcy000') result = sqlhelper.all(query, [name]) if (len(result) == 0): print('用户不存才') elif result[0][0] == pwd2: print('登录成功') else: print('密码错误') print(result)
#coding=utf-8 from MysqlHelper import * #修改 #name = input('请输入学生姓名') #id1 = input('请输入学生编号') #sql = 'update students set sname=%s where id=%s' #params = [name,id1] #sqlhelper = MysqlHelper('localhost',3306,'python3','root','mysql') #sqlhelper.cud(sql,params) #查询 sql = 'select id, sname from students where id < 3' sqlhelper = MysqlHelper('localhost', 3306, 'python3', 'root', 'mysql') result = sqlhelper.all(sql) print(result)
#encoding=utf-8 from MysqlHelper import * id1=input('请输入学号') name =input('请输入名字') sql='update tb_info set infoname=%s where id=%s' params=[name,int(id1)] sqlhelper=MysqlHelper('localhost',3306,'pymysql','root','kcy000') sqlhelper.cud(sql,params) query='select * from tb_info' param=[] print(sqlhelper.all(query,param))