zoukankan      html  css  js  c++  java
  • 利用python实现简单登陆注册系统

     1 #!/usr/bin/env python
     2 # -*- coding:utf-8 -*-
     3 
     4 
     5 def login(username,password):
     6     '''
     7 
     8     :param username:用户名
     9     :param password:密码
    10     :return: True:登陆成功  False:登陆失败
    11     '''
    12     f = open('log','r',encoding='utf-8')
    13     for line in f:
    14         line = line.strip()
    15         line_list = line.split('$')
    16         if username ==line_list[0] and password ==line_list[1]:
    17             print('success')
    18             return True
    19         return False
    20 
    21 def register(username,password):
    22     '''
    23 
    24     :param username:
    25     :param password:
    26     :return:
    27     '''
    28     with open('log','a',encoding='utf-8') as f:
    29         temp = '
    ' + username + '$' + password
    30         f.write(temp)
    31     return True
    32 
    33 def user_exit(username):
    34     '''
    35 
    36     :param username:
    37     :return:
    38     '''
    39     with open('log','r',encoding='utf-8') as f:
    40         for line in f:
    41             line = line.strip()
    42             line_list = line.split('$')
    43             if line_list[0]==username:
    44                 return True
    45     return False
    46 
    47 def main():
    48     print('欢迎登陆XX系统')
    49     inp = input('1:登陆;2:注册')
    50     user = input('user:')
    51     pwd = input('pwd:')
    52     if inp =='1':
    53         is_login = login(user,pwd)
    54         if is_login:
    55             print('success')
    56         else:
    57             print('fail')
    58     elif inp =='2':
    59         is_exit = user_exit(user)
    60         if is_exit:
    61             print('already register')
    62         else:
    63             result = register(user,pwd)
    64             if result:
    65                 print('register sucess')
    66             else:
    67                 print('resgister faild')
    68 main()
  • 相关阅读:
    css中的属性
    css初识和css选择器
    前端html的简单认识
    数据库进阶了解
    数据库索引
    pymysql模块
    数据库的多表查询
    数据库中的行操作
    数据库和表操作以及完整性约束
    数据库概述
  • 原文地址:https://www.cnblogs.com/Erick-L/p/6399530.html
Copyright © 2011-2022 走看看