Q. Write a program that asks a new user about userid and password and then appends it to file “security. txt” provided the give userid does not exist in the file . If it does, then display error message “User id already exist”and prompt the user to re-enter the userid. Also, make sure that the password is a least 8 characters long with at least a digit and a special character out of “$, @and %” in it.

 

Answer = 

 



def password():
    psd= input ("Enter the password :- ")
    if len(psd) >= 8 and ("$" in psd or "@" in psd or "%" in psd):
        print (" Done ")
        file.write(userid + "  " + psd + "\n")
    else :
        print ("Re-enter the password")
        password()
        
file = open("security.txt","r+")
text = file.readlines()
userid = input("Enter userID : - ")
same = 0
for i in text:
    line = i.split()
    if line[0] == userid:
        same = 1
        print ("User id already exist")
if same == 0 :
    password()

file.close()

 

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post