• 注册-登录-数据都存在数据库里面-注册的时候,密码存的是加密之后的密码-登录成功之后打印当前的日期


    # 3、 注册
    # 登录
    # 数据都存在数据库里面
    # idusernamepasswd
    # 注册的时候,密码存的是加密之后的密码
    # usernamepwdcpwd, 都是必填的
    # 用户不能重复
    # 登录
    # 账号
    # 密码
    # 登录成功之后打印当前的日期

    import hashlib,pymysql,datetime
    def my_db(sql):
    import pymysql
    coon = pymysql.connect(
    host='118.xx.xx.xx', user='xxx', passwd='123456',
    port=3306, db='xxx', charset='utf8')
    cur = coon.cursor() #建立游标
    cur.execute(sql)#执行sql
    if sql.strip()[:6].upper()=='SELECT':
    res = cur.fetchall()
    else:
    coon.commit()
    res = 'ok'
    cur.close()
    coon.close()
    return res

    def my_md5(str):
    import hashlib
    new_str = str.encode() #把字符串转成bytes类型
    # new_str = b'%s'%str #把字符串转成bytes类型
    m = hashlib.md5() #实例化md5对象
    m.update(new_str) #加密
    return m.hexdigest() #获取结果返回

    def reg():
    username = input('username:').strip()
    pwd = input('pwd:').strip()
    cpwd = input('cpwd:').strip()
    if username and pwd and cpwd:
    sql = 'select * from nhy where name="%s";'%username
    # select * from nhy where name='nhy';
    res = my_db(sql)
    if res:
    print('该用户已经存在!')
    else:
    if pwd == cpwd:
    md5_pwd = my_md5(pwd)
    insert_sql = 'insert into nhy (name,pwd) value ("%s","%s");'%(username,md5_pwd)
    my_db(insert_sql)
    print('注册成功!')
    else:
    print('两次输入的密码不一致')
    else:
    print('必填项不能为空!')

    def login():
    username = input('username:').strip()
    pwd = input('pwd:').strip()
    if username and pwd:
    md5_pwd = my_md5(pwd)
    sql = 'select * from nhy where name="%s" and pwd="%s";'%(username,md5_pwd)
    # select * from nhy where name='nhy';
    res = my_db(sql)
    if res:
    print('欢迎,登录成功!今天是%s'%datetime.date.today())
    else:
    print('账号/密码错误!')
    else:
    print('必填项不能为空!')
    login()

  • 相关阅读:
    38. Count and Say(C++)
    35. Search Insert Position(C++)
    29. Divide Two Integers(C++)
    c++读取utf-8格式中英文混合string
    一种局部二值化算法:Sauvola算法
    Ubuntu 1804 本地显示远程服务器文件
    caffe 预训练 或者Fine-Tuning 操作
    caffe/blob.hpp:9:34: fatal error: caffe/proto/caffe.pb.h: 没有那个文件或目录
    转载---LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别
    [leetcode-921-Minimum Add to Make Parentheses Valid]
  • 原文地址:https://www.cnblogs.com/jiadan/p/9033457.html
Copyright © 2020-2023  润新知