Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Coding issue
Hi guys! I'm new to python and coding in general. I'm trying to make a program which will register new users and login registered users. My issue is when I register a user using the program and attempt to login using the same username and password, the print says 'access denied' instead of what it should say, 'access granted'. I don't know what's the issue here. It would be great if you guys could help. Thanks! Here is the code:
a = input('Logging in or new user')
registration = []
passwords = []
if a == 'logging in':
    b = input('username')
    c = input('password')
    if b in registration:
        if c in passwords:
            print('Access granted')
            print('Access Denied')
        print('Access Denied')

if a == 'new user':
    d = input('New username')
    e = input('New password')
    f = input('confirm password')
    if e == f:
        print('Welcome ' + d)
(edit: everything is properly indented)

Thank you Yoriz! I will follow these instructions next time.
Yoriz wrote Aug-02-2019, 06:50 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Each time you run this code, the lists will be empty.
There is no loop to enable a login after a user has been added without the code ending.
Note: your logic will allow any username matched with any password to login.
You can use dict to store usernames and passwords instead of list, and save dict to a file and load it each time when you run the *program check my example bellow

import json
import os 

auth_file = "auth.json"
auth = None

def loadAuth():
    if os.path.isfile(auth_file):
        return eval(open(auth_file).read())
    return {}

def saveAuth():
    json.dump(auth, open(auth_file, 'wt'))

if __name__ == '__main__':
    auth = loadAuth()

    operation = input('Login in or new user: ')

    if operation == 'login':
        username = input('username: ')
        password = input('password: ')

        if username in auth.keys() and auth[username] == password:
            print('Access granted')
            print('Access Denied - Wrong username or password')

    elif operation == 'new user':
        username = input('New username: ')
        password = input('New password: ')
        password_conf = input('confirm password: ')

        if password == password_conf:
            if username not in auth.keys():
                auth[username] = password
                auth == loadAuth()
                print('Welcome ' + username)
                print (username,auth[username])
                print ("Username already exists")

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python Coding Issue! ankitdixit 3 343 Sep-25-2019, 06:31 AM
Last Post: rohanjoshi0894
  New member with simple coding issue shaikh 0 1,542 Apr-24-2017, 05:28 PM
Last Post: shaikh
  coding issue Lee 2 1,362 Feb-13-2017, 10:53 AM
Last Post: Lee

Forum Jump:

Users browsing this thread: 1 Guest(s)