zoukankan      html  css  js  c++  java
  • 用户登陆系统

    1.最基础的,用户名密码放到一个文件里,可以注册登陆查询注册用户名是否重复

    def login(username, password):
        '''
        登录
        :param username:用户输入的用户名
        :param password: 用户输入的密码
        :return:验证成功
        '''
        with open('userinfo.txt', 'r', encoding='utf-8') as oplogin:
            for line in oplogin:
                if line.split('%%')[0] == username and line.split('%%')[1] == password:
                    return True
        return False
    
    
    def register(username, password):
        '''
        注册
        :param username: 用户输入的用户名
        :param password: 用户输入的密码
        :return: 写入文件注册成功
        '''
        with open('userinfo.txt', 'a', encoding='utf-8') as opreg:
            opreg.write('
    ' + username + '%%' + password)
            return print('注册成功')
    
    
    def same(username):
        '''
        查是否重复用户名
        :param username: 用户输入用户名
        :return:如果重复返回True,没有重复返回Flase
        '''
        with open('userinfo.txt', 'r', encoding='utf-8') as opsame:
            for line in opsame:
                line = line.strip()
                if line.split('%%')[0] == username:
                    return True
        return False  # 这个return要在最外层,而不是在if语句里
    
    
    def main():
        choice = input('1:login,2:register')
        if choice == '1':
            username = input('username')
            password = input('password')
            if login(username, password):
                print('登录成功')
            else:
                print('登录失败')
        if choice == '2':
            username = input('username')
            password = input('password')
            if same(username):
                print('用户名已被占用')
                main()
            else:
                register(username, password)
    
    
    main()
  • 相关阅读:
    关于分布式的一些理解和认识
    Git使用详细教程
    Kettle 7启动 Spoon.bat 时报错“A Java Exception has occurred.”的解决方法
    postgresql 9源码安装
    intel笔记本cpu型号后缀详解(M,U,QM,MQ,HQ,XM)
    LAMP部署流水
    四种mysql存储引擎
    MySQL日志
    MySQL存储引擎总结
    MySQL存储引擎中的MyISAM和InnoDB
  • 原文地址:https://www.cnblogs.com/xusuns/p/8323685.html
Copyright © 2011-2022 走看看