简体   繁体   中英

Random Dictionary Login System Python

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 them, 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.

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)
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")
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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM