Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Login System
#1


Can someone help me finish off the code/fix it? So if you say "n", you will register, and a .txt is created then it will prompt you to login. However, if you enter "y", and enter correct details it will say "welcome and "incorrect username or password". I need it to be a loop, and also in similar formats to how it's orgiinally written - yes I know there are ways of using excel etc but I have to use .txt for a school project. Try it below:


import time

time.sleep(1)
print("Welcome...")
welcome = input("Do you have an acount? y/n")
if welcome == "n":
username = input("Enter a username:")
password = input("Enter a password:")
password1 = input("Confirm password:")
if password != password1:
print("Passwords do NOT match!")
username = input("Enter a username:")
password = input("Enter a password:")
password1 = input("Confirm password:")
text_file = open(username+ ".txt", "w")
text_file.write(username+":"+password)
text_file.close()
login1 = input("Login:")
login2 = input("Password:")
f = file = open(login1+".txt", "r")
if(file.readline())== (login1+":"+login2):
print("Welcome")

if welcome == "y":
login1 = input("Login:")
login2 = input("Password:")
f = file = open(login1+".txt", "r")
if(file.readline())== (login1+":"+login2):
print("Welcome")
if(file.readline())!= (login1,":",login2):
print("Incorrect username or password.")
time.sleep(1)
login1 = input("Login:")
login2 = input("Password:")
text_file = open(login1+ ".txt", "r")
login1 = input("Login:")
login2 = input("Password:")
f = file = open(login1+".txt", "r")




#textfile.write(username+ ""+password)
#print line.split(":::::"
Reply
#2
#!python3

print("Welcome...")
welcome = input("Do you have an acount? y/n: ")
if welcome == "n":
    while True:
        username  = input("Enter a username:")
        password  = input("Enter a password:")
        password1 = input("Confirm password:")
        if password == password1:
            file = open(username+".txt", "w")
            file.write(username+":"+password)
            file.close()
            welcome = "y"
            break
        print("Passwords do NOT match!")

if welcome == "y":
    while True:
        login1 = input("Login:")
        login2 = input("Password:")
        file = open(login1+".txt", "r")
        data   = file.readline()
        file.close()
        if data == login1+":"+login2:
            print("Welcome")
            break
        print("Incorrect username or password.")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 5,339 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Login and Register system finndude 1 587 Apr-24-2020, 10:05 PM
Last Post: deanhystad
Question Difference between Python's os.system and Perl's system command Agile741 13 1,614 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Login system not working Unknown_Relic 2 633 Nov-05-2019, 12:07 PM
Last Post: buran
  Login System Carbonix 4 1,773 Feb-04-2019, 02:19 PM
Last Post: Larz60+
  Python login system help. calumw20 1 1,654 Mar-06-2018, 08:01 AM
Last Post: buran
  Creating a Login System Using Python- HELP tesilstudent112 0 7,528 Dec-08-2017, 07:17 PM
Last Post: tesilstudent112

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020