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()
  • 相关阅读:
    操作系统的磁盘结构、磁盘管理、磁盘调度算法
    ArrayList源码解析--值得深读
    深入理解static、volatile关键字
    7:高阶张量操作
    6:统计属性
    5:张量的基本运算
    4.1张量的操作(broadcasting维度自动扩张,拼接与拆分)
    4:张量操作
    3:索引与切片
    2:pytorch的基本数据类型以及张量的创建
  • 原文地址:https://www.cnblogs.com/xusuns/p/8323685.html
Copyright © 2011-2022 走看看