13.Python Full Stack Road: User Login Program

Source: Internet
Author: User

User Login Program

Feature Description:

1. Support Login Verification

2. Support to register new users

#!/usr/bin env python#-*-coding:utf-8-*-def Login (user, PWD): "" "Authentication for User name password:p Aram User: Username:p aram PWD: Secret            Code: Return:true, user authentication succeeded, flase, user authentication failed "" "with Open (" Db.log "," R ", encoding=" Utf-8 ") as F:for line in F:            line = Line.strip () # Remove both ends of the newline and null characters for the default strip parameter: Remove spaces and newline characters with parameters: Removes the values specified on both sides                "' Line_list = Line.split (" $ ") if user = = Line_list[0] and pwd = = Line_list[2]: Return True return Falsedef register (username, password): "Registered user:p Aram Username: User name:p aram password : Password: Return: Registered success true ' with open ("Db.log", "a", encoding= "Utf-8") as F:temp = "\ n" + Username + "$" + p    Assword F.write (temp) return truedef user_exist (username): "" "Determines whether the user exists:p Aram Username:: return: "" With Open ("Db.log", "R", encoding= "Utf-8") as F:for line in f:line = Line.strip () l Ine_list = Line.split ("$") if line_list[0] = = Username:return True return falsedef main (): print (" Welcome login XXX System ") INP = Input ("1: Login; 2: Register") If InP = = "1": User = input ("Please enter User:") pwd = input ("Please enter password:") Is_login = Lo        Gin (user, PWD) if Is_login:print ("Login Successful") Else:print ("Login Failed") elif INP = = "2": user = input ("Please enter User:") pwd = input ("Please enter password:") is_exist = user_exist (user) if Is_exist:p Rint ("User already exists, unable to register") Else:result = Register (username, pwd) if Result:print ("registered successfully" ) Else:print ("Registration Failed") Main ()

  

13.Python Full Stack Road: User Login Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.