The first to complete the program: Register Login achieved through files

The main function:

import log on 
the User = the INPUT ( ' Please enter your user name: ' ) 
PSW = the INPUT ( ' Please enter your password: ' ) 

Login .log_in (user, psw)

Log function

import register
def log_in(user:str,psw:str):
    with open('aa.txt', 'r', encoding='utf-8') as f:
       for res in f:
           res = res.strip('\n')
           res_list = res.split(',')
           res_name=res_list[0].split(':')
           res_psw=res_list[1].split(':')
           if user==res_name[1].strip(' '):
               if psw == res_psw[1].strip('\n'):
                   print("ok")
                   break
               else:
                   print("password error")
                   break
       else:
           print("用户名不存在,请注册")

           register.register()

  Registration function

DEF Register (): 
    COUNT =. 1 
    User = INPUT ( 'Enter Username:') 
    the while True: 
        PSW = INPUT ( 'Enter password:') 
        PSW1 = INPUT ( 'Please enter your password:') 
        IF COUNT> 2 : 
            Print ( "more than three times the number of errors") 
            BREAK 
        IF PSW == PSW1: 
            USER_INFO = F 'username: {user}, password: {} PSW' 

            with Open ( 'aa.txt', 'R & lt', encoding = ' . 8-UTF ') AS F: 
                for RES in F: 
                    res_list res.split = (', ') 
                    RES_NAME res_list = [0] .split (': ') 
                    IF == User RES_NAME [. 1] .strip (): 
                        Print ( "username already exists, please re-enter") 
                        User = INPUT ( 'Enter Username:')
                        . 1 = COUNT 
                        BREAK 
                the else: 
                    with Open ( 'aa.txt', 'A', encoding = 'UTF-. 8') AS F: 
                        f.write (USER_INFO + '\ n-') 
                        Print ( "registration is successful") 
                        BREAK 
        the else: 
            =. 1 + COUNT 
            Print ( 'passwords do not match, please re-enter ")

  

 

Guess you like

Origin www.cnblogs.com/evan0925/p/11013217.html