repl.it
@pieromqwerty/

Username and Password

Python

does what it says on the tin

fork
loading
Files
  • main.py
  • passwords
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import colors
import os
import time

def clear():
  os.system("clear")

def signup():
#sign up
  clear()
  print("Sign up now!")
  while True: 
    email = input(str("Enter your email: "))
    c = email.find("@")
    e = email.find(".")
    if (c > -1) and (e > -1) and '' in email:
      break
    else:
      print(colors.red("Invalid Email."))

  while True:
    password = input(str("Enter your password: "))
    if len(password) <= 3:
      print(colors.red("Invalid Password. Reason: Less than 3 characters"))
    else:
      break

  file = open("passwords", "a")
  file.write(email)
  file.write(" ")
  file.write(password)    
  file.write("\n")
  file.close()

  print(colors.green("Success"))


def login():
    clear()
    print("Log In!")
    email = input("email: ")
    password = input("password: ")  
    for line in open("passwords","r").readlines():
        login_info = line.split()
        if email == login_info[0] and password == login_info[1]:
            print(colors.green("Login Succesful!"))
        else:        
            print(colors.red("Login Failed."))

while True:
  loginsignup = input("Do you want to log in or sign up? ").lower()
  if loginsignup == "sign up":
    signup()         
    time.sleep(2)
    print(colors.green("Redirecting you to the login page."))
    time.sleep(2)                    
    clear()
    login()
    break

  if loginsignup == "log in":
    login()
    break
  
  else:
    print(colors.red("Invalid Command!"))