Home > front end >  Random Dictionary Login System Python [ Need Solution ]
Random Dictionary Login System Python [ Need Solution ]

Time:12-17

I want to create the Login System that will use Random Dictionary.The Problem is accessing the Elements of the Dictionary after making it select random elements.I will continue trying to find the Answer, but I want to post this problem here as there could be someone else with the similar problem and this could help him, and you may answer before I find the right way of access.

import time
import random
import string

d = {
    'l1' : 'p1', 'l2' : 'p2'
}

d1 = random.choice(list(l.items()))

def d2(l, p):
    d_l = print(l)
    d_p = input("Enter the Answer: ")

    if d_p == p:
        print("Login Successful.")
    else:
        print("Your Answer was not correct.")
        print("Process will be terminated")
        time.sleep(5)

d2(#Here is the Problem)

I tried accessing using iter, although I know it's Impossible.

CodePudding user response:

Solution for this Problem is:

import time
import random

d = {
    'l1' : 'p1', 'l2' : 'p2'
}

key, value = random.choice(list(d.items()))
def d2(l, p):
    d_l = print(l)
    d_p = input("Enter the Answer: ")

    if d_p == p:
        print("Login Successful.")
    else:
        print("Your Answer isn't correct.")
        print("Process will be terminated")
        time.sleep(5)

d2(key, value)

CodePudding user response:

def getlogins():
  from requests import get
  return get(url).text

logins = getlogins()
logins = logins[:-1]
username = input("Username:")
username = str(username)
password = input("Password: ")
password = str(password)

if password == logins[username]:
    print("Logged in!")
else:
    print("Wrong password or username")

CodePudding user response:

def getlogins(url):
    from requests import get
    return get(url).text

logins = getlogins()
logins = logins[:-1]
username = input("Username:")
username = str(username)
password = input("Password: ")
password = str(password)

if password == logins[username]:
    print("Logged in!")
else:
    print("Wrong password or username")
  • Related