I'm trying to make a simple program that prompts for a password and then continues to a different section of the program, else loops back to the original prompt for the password.

I can't find a way to do this other than to use external things - such as text documents and buttons - and I don't need the password to be encoded. I just want it to show up right away without adding text files or buttons.

Such as:

Enter password: "hi"

if the password is "hi" it continues on

if the password is anything else it loops back to

Enter Password:

Can this be done? Ideas?

Recommended Answers

All 2 Replies

You would use a while() loop or function for this, Search the web for either as there are many examples of password entry. Some pseudo-code

def get_pw():
    while 1:
        pw=raw_input()
        if pw is correct:
            return

A while loop ended up being what saved me mounds of frustration. I simplified it with:

while password != "hello":
    password = raw_input("Please Enter Password: ")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.