Simple Python user logon and registration, python User Logon
#! /Bin/bash/env python #-*-coding: UTF-8-*-def login (username, password): "Logon for username and password: param username: param password: return: True, user verification successful; False, Verification Failed "with open ('cai. log', 'R', encoding = "UTF-8") as f: for line in f: # Reading line = line for a row. strip () # Remove spaces at both ends and linefeed line_list = line. split ("$") # split with the $ symbol if username = line_list [0] and password = line_list [1]: return True return Falsedef register (username, password ): "Registered User: param username: User name: param password: return: True, registration successful" with open ('cai. log', "a", encoding = "UTF-8") as f: temp = "\ n" + username + "$" + password f. write (temp) return Truedef user_exist (username): "check whether the user already exists: param username: User name: return: True, the user name already exists; False, the user name does not exist "" with open ('cai. log', "r", encoding = "UTF-8") as f: for line in f: line = line. strip () line_list = line. split ("$") if username = line_list [0]: return True return Falsedef main (): print ("welcome to the Swiss system") indium = input ("1: login; 2: register ") user = input (" Enter the user name: ") pwd = input (" enter the password: ") if indium =" 1 ": is_login = login (user, pwd) if is_login: print ("Logon successful") else: print ("Logon Failed") elif indium = "2 ": is_exist = user_exist (user) if is_exist: print ("the user already exists and cannot be registered") else: result = register (user, pwd) if result: print ("registered successfully ") else: print ("registration failed") main ()