from mysqlpython import MysqlPython sqlh = MysqlPython("danei") upd = "update t1 set t1name='C2' where t1name='B2'" sqlh.execute(upd) sql = "select * from t1" print(sqlh.All(sql))
# pwd1 = input("请输入密码: ") # pwd2 = input("请再次输入密码: ") # # if pwd1 == pwd2: # #把密码加密存入数据库 # #创建加密对象 # s = sha1() # #加密,参数一定要为bytes数据类型 # s.update(pwd1.encode("utf-8")) # #返回十六进制加密结果 # pwd = s.hexdigest() # ins = 'insert into user values(%s,%s)' # sqlh.execute(ins,[uname,pwd]) # print("注册成功") # else: # print("两次密码不一致") #用户登录 sele = "select password from user where username=%s" r = sqlh.All(sele, [uname]) pwd = input("请输入密码: ") s = sha1() s.update(pwd.encode("utf-8")) pwd = s.hexdigest() if len(r) == 0: print("用户名错误") elif pwd == r[0][0]: print("登录成功") else: print("密码错误")