将正确的结果传递出身份验证循环

时间:2019-01-06 19:42:48

标签: python loops

我正在创建一个登录系统,该系统将检索输入框中的详细信息并将其与数据库中的详细信息进行比较。如果在数据库上找到输入的详细信息,则运行Bottom()函数。如果找不到详细信息,则要求用户重试。

当前,程序会循环运行直到找到它。但是,由于我建立了else语句,如果数据库中的第一项不是输入的详细信息,则else部分仍将运行。有什么办法可以更改此设置,以使elseelse last value in the database?

功能如下:

#Retrieves the information entered into entry box
def Get_Details():
    user_namev2=user_name.get().lower() #Make it so entry box goes red if passwords password is incorrect, and red if username is incorrect/not fault
    user_passwordv2=user_password.get().lower()
    with open ('Accounts.csv', 'r') as Account_file:
        reader = csv.reader(Account_file)
        for row in reader:
            for field in row:
                if row[0] == user_namev2 and row[1] == user_passwordv2:
                    Bottom()
                    break
                else:
                    nomatch_label = Label(canvas, width = 40, height = 2, text = "USERNAME AND PASSWORD NOT FOUND", fg = "red", bg = "gray21", font = font2)
                    canvas_nomatch_label = canvas.create_window(500, 550, window = nomatch_label)
                    name_entry.config(fg = "red")
                    password_entry.config(fg="red")
                    break

2 个答案:

答案 0 :(得分:1)

这应该可以按照您期望的方式工作,现在它遍历行并针对static class Design { private static readonly PrivateFontCollection Fonts = new PrivateFontCollection(); public static readonly Font SerifFont; static Design() { Fonts.AddFontFile(@"c:\some_font.ttf"); SerifFont = new Font(Fonts.Families[0], 12); } } function deepest_child(param) { var element_list = $(param) var depth = 0 var deepest_element element_list.each( function (index) { this_depth = $(this).parents().length if (this_depth > depth) { depth = this_depth deepest_element= $(this) } }) return deepest_element } 检查用户名/密码。如果找到匹配项,它将中断并不会执行连接到for循环的else。

我还删除了row[0]上的for循环,因为无论如何都没有使用row[1]变量。

row

答案 1 :(得分:0)

#Retrieves the information entered into entry box
def Get_Details():
    user_namev2=user_name.get().lower() #Make it so entry box goes red if passwords password is incorrect, and red if username is incorrect/not fault
    user_passwordv2=user_password.get().lower()
    with open ('Accounts.csv', 'r') as Account_file:
        reader = csv.reader(Account_file)
        found = False
        for row in reader:
            for field in row:
                if row[0] == user_namev2 and row[1] == user_passwordv2:
                    Bottom()
                    found = True
                    break

            else:
                if not found:
                    nomatch_label = Label(canvas, width = 40, height = 2, text = "USERNAME AND PASSWORD NOT FOUND", fg = "red", bg = "gray21", font = font2)
                    canvas_nomatch_label = canvas.create_window(500, 550, window = nomatch_label)
                    name_entry.config(fg = "red")
                    password_entry.config(fg="red")
                    break

请注意,else已移回与for循环配对的位置