def main(): time_start = time.time() insert_data = MySQLHelper('192.168.126.129', 3306, 'stu_info', 'root', '12345') print("="*50) acount = input("请输入账户名:") paras = [acount] sql = "select * from csdn_sha1 where account = %s" res = insert_data.get_one(sql,paras) print(res) if res == None: print("+"*50) print("账号不存在,请核实") else: print("+"*50) pwd = input("请输入密码:") # 加密算法 s = sha1() s.update(pwd.encode('utf-8')) pwd = s.hexdigest() print(pwd) # 与数据库中已经加密过的对比 if pwd == res[2]: print("+"*50) print("登陆成功") else: print("+"*50) print("密码错误,请核实") time_end = time.time()
def main(): time_start = time.time() insert_data = MySQLHelper('192.168.126.129', 3306, 'stu_info', 'root', '12345') acount = input("请输入账户名:") paras = [acount] sql = "select * from csdn where account = %s" res = insert_data.get_one(sql, paras) print(res) if res == None: print("账号不存在,请核实") else: pwd = input("请输入密码:") if pwd == res[2]: print("登陆成功") else: print("密码错误,请核实") time_end = time.time() print("结束查找,总共花费时间为%0.2f" % (time_end - time_start))
def main(): time_start = time.time() insert_data = MySQLHelper('192.168.126.129', 3306, 'stu_info', 'root', '12345') sql = "insert into csdn_sha1(account,passwd,email) values(%s,%s,%s)" f = open('csdn.txt', 'r', encoding='utf-8') if not f: print("打开失败") print("插入数据") while True: try: string = f.readline() pattern = re.compile(" # ") paras = re.split(pattern, string) # 新建加密对象 s = sha1() s.update(paras[1].encode('utf-8')) paras[1] = s.hexdigest() if len(string) <= 0: print("读取完成") break elif len(paras): insert_data.edit(sql, paras) insert_data.is_ok() except Exception as e: print(e) pass time_end = time.time() print("结束插入,总共花费时间为%0.2fh" % ((time_end - time_start) / 360))
def main_demo(): insert_data = MySQLHelper('192.168.126.129', 3306, 'stu_info', 'root', '12345') sql = "insert into student(name) values('刘备')" insert_data.edit(sql, []) insert_data.is_ok() print('插入完成')
def main(): insert_data = MySQLHelper('192.168.126.129', 3306, 'stu_info', 'root', '12345') sql = "insert into csdn(account,passwd,email) values(%s,%s,%s)" f = open('csdn.txt', 'r', encoding='utf-8') if not f: print("打开失败") while True: try: string = f.readline() pattern = re.compile(" # ") paras = re.split(pattern, string) if len(string) <= 0: print("读取完成") break else: # print(paras) insert_data.edit(sql, paras) except Exception as e: print(e) pass
def main3(): insert_data = MySQLHelper('192.168.126.129', 3306, 'stu_info', 'root', '12345') sql = "create table csdn_sha1(id int auto_increment primary key not null, account varchar(20), passwd char(40), email varchar(45))" insert_data.edit(sql, [])