Python Forum
My very first "thing" what I'm somewhat proud of, after a week udomy class. Register
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My very first "thing" what I'm somewhat proud of, after a week udomy class. Register
#1
import time
def log_in ():
    return ()
 
print("Register:")
ui = []
pw = []
while True == 1:
    userid = input("Give you User name: " )
    password = input("Give your password: ")
     
    if userid in ui:
            print('Userid already in use!')
            True == 1
    else:
        print('You registered successfully!!')
        ui.insert(0, userid)
        pw.insert(0, password)
        #print (ui)
        #print (pw)
        #True == 1
        break
time.sleep(2)
import os 
os.system('clear')
while True == 1:
    print("Log In:")
    if input("User ID: ") in ui:
            if input("Password: ") in pw:
                print("Succesfull LogIn!")
                 
                import webbrowser
                webbrowser.open('http://www.youtube.com', new=2)
                break
                True == 4
            else:
                print("Wrong User name or password!! Try again!!")
Reply
#2
(Jun-16-2020, 11:30 AM)Haulpa Wrote: My very first "thing" what I'm somewhat proud of, after a week udomy class. Register
Yes you should be proud of it Thumbs Up
A quick look fixing some stuff like all imports first and while True without == 1 is enough.
Try to keep 4-space indentation in all code blocks.

The logic is okay for one time run trough,but will never reach these lines.
if userid in ui:
    print("Userid already in use!")
Then need to save ui and pw to disk,which good be an improvement.
Also a menu of that's tell what's logging into would help,then could also looking at using functions for this.

Here is the clean up,not doing any extra stuff as mention over.
import time
import os
import webbrowser

ui = []
pw = []
print("Register:")
while True:
    userid = input("Give you User name: ")
    password = input("Give your password: ")
    if userid in ui:
        print("Userid already in use!")
    else:
        print("You registered successfully!!")
        ui.insert(0, userid)
        pw.insert(0, password)
        break

time.sleep(2)
os.system("clear")
while True:
    print("Log In:")
    if input("User ID: ") in ui:
        if input("Password: ") in pw:
            print("Succesfull LogIn!")
            webbrowser.open("http://www.youtube.com", new=2)
            break
        else:
            print("Wrong User name or password!! Try again!!")
Reply
#3
Thanka your advice!

I know it is ok for 1 time run through this is why I left this lines:

#print (ui)
#print (pw)
#True == 1

For repeat and see if I can save ui and pw in a list.

I just wanted for now figure out how is all done and actually I have no idea yet how I can save them to disk ? but I will check.
Reply
#4
In line 17 and 19 what can i do for when i run first time it creat the file and it can read it but when i run it again dont over write it? Right now if i run it first time it says the file dosn`t exit because it read only, but if i change to write the first time it is runing ok but the secound time it cant read it.
I hope i explaind it clear
import time
import os
import webbrowser
import smtplib, ssl

port = 465

context = ssl.create_default_context()

arroba = '@'
point = '.'
print("Register:")
while True:
    userid = input("Give you User name: ")
    password = input("Give your password: ")
    email = input("Your email: ")
    emailfile = open('emailfile.txt', 'r') #email of "client"
    emailcontent = emailfile.read()
    userfile = open('userfile.txt', 'r')
    uicontent = userfile.read()	
    if userid in uicontent:
    	print("Userid already in use!")
    elif len(password) < 5:
    	print('Too short password, minimum 5 character')
    elif arroba not in email:
    	print('Not valid email!')
    elif point not in email:
    	print('Not valid email')
    elif email in emailcontent:
    	print('Email already in use!!')
    else:
        	 	with open ('userfile.txt', "a+") as f:
        	 		f.write (''.join (userid) + '\n');
        	 	with open ('passfile.txt', "a+") as f:
        	 		f.write (''.join (password) + '\n')
        	 	with open ('emailfile.txt', "a+") as f:
        	 		f.write ("".join(email) + '\n')
        	 	print("You registered successfully!!")
        	 	ui.insert(0, userid)
        	 	pw.insert(0, password)
        	 	sender_email = "email_of the sender"  #company email
        	 	password = 'sender_email_password' #company email password
        	 	receiver_email = email  # Enter client address
        	 	message = "You registered successfully" # sent massage
        	 	with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
        	 		server.login(sender_email, password)
        	 		server.sendmail(sender_email, receiver_email, message)
        
        	
        	 	break
 
time.sleep(2)
os.system("cls")
while True:
    uicheck =  open ('userfile.txt', 'r')
    uicheck2 = uicheck.read()
    pwcheck = open('passfile.txt', 'r')
    pwcheck2 = pwcheck.read()
    print("Log In:")
    if input("User ID: ") in uicheck2:
    	       if input("Password: ") in pwcheck2:
    	       		print("Succesfull LogIn!")
    	       		webbrowser.open("http://www.youtube.com", new=2)
    	       		break
    	       else:
    	       	print("Wrong User name or password!! Try again!!")
    else:
            print("Wrong User name or password!! Try again!!")

You have to delete line 39 and 40 bacause i left it inside...
ui.insert(0, userid)
pw.insert(0, password)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  My very first "thing" what I'm somewhat proud of, after a week udomy class. Register Haulpa 5 3,638 Aug-26-2020, 08:54 AM
Last Post: buran
  my first attempt, please advise me of any thing danak 6 3,886 Feb-01-2020, 03:19 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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