Login system with infinite loop error
<p>I'm coding myself a "simple" login system everything works ok up until the <code>LOGIN</code> part.</p>

<p>The <code>while</code> loop at the end only happens once even though I put another user rather than what I created when I ran the program. I got it to work at some point, but then there was another issue where the <code>while</code> loop would happen over and over again.</p>

<pre><code>import re
users = {}
status = ""


while status != "r":
    status = input("Press R to register!\n")

    if status == "r":
        createUser = input("Create your Username: ")
        while len(createUser)&lt; 5:                                   #checks user len
            print("Username should contain at least 5 characters!")

            createUser = input("Create your Username: ")            #repeat if user len &lt; 5

        while not re.match("^[a-z]*$" , createUser):                   # denies blank spaces
            print("Cannot use blank spaces")
            createUser = input("Create your Username: ")

        if createUser in users:
            print("Username already used!")
        else:
            createPass = input("Create your Password: ")
            while len(createPass) &lt; 5:                              #checks pass len
                print("Password too short!\n          Password should contain at least 5 characters!\n")
                createPass = input("Create your Password: ")        #repeat if pass len &lt; 5

            while not re.match("^[a-z]*$", createPass):  # denies blank spaces
                print("Cannot use blank spaces")
                createPass = input("Create your Password: ")


            else:
                users[createUser] = createPass  #adds user and pass to users
            print("User created!")

        #LOGIN
            for createUser in users:
                username = input("Username: ")
                if username == createUser in users:
                    password = input("Password: ")
                else:
                    while username != createUser:
                        print("User unregistered! Please register!")
                        createUser = input("Create your Username:")
</code></pre>

<p>First, <code>"^[a-z]*$"</code> tests for no lowercase letters, it does not mean "no blank spaces", so I have corrected that for you with <code>"\\s+"</code></p>

<p>You really need to learn about methods and break your problem down. </p>

<p>1) Ask for the username</p>

<pre><code>def get_username():
    while True:
        uname = input("Create your Username: ")
        if len(uname) &lt; 5:
            print("Username should contain at least 5 characters!")
            continue
        if re.search("\\s+", uname):
            print("Cannot use blank spaces")
            continue
        break # input successful
    return uname
</code></pre>

<p>2) Ask for the password</p>

<pre><code>def get_password():
    while True:
        passwd = input("Create your Password: ")
        if len(passwd) &lt; 5:
            print("Password too short!\n\tPassword should contain at least 5 characters!\n")
            continue
        if re.search("\\s+", passwd):
            print("Cannot use blank spaces")
            continue
        break # input successful
    return passwd
</code></pre>

<p>3) Register</p>

<pre><code>def register():
    while True:
        uname = get_username()
        if uname not in users:
            break  # continue to get password
        else:
            print("Username already used!")

    passwd = get_password()
    if passwd:
        users[uname] = passwd
    print("User created!")
</code></pre>

<p>4) Attempt login (3 max attempts). It is currently unclear how you want to run this... </p>

<pre><code>def login():
    for i in range(3):
        username = input("Username: ")
        if username in users:
            password = input("Password: ")
            if users[username] != password:
                print("Wrong username or password")
        else:
            print("User does not exist")
    else:
        print("Max attempts reached")
</code></pre>

<p>5) (optional) Learn about <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">D.R.Y</a> since your tests are essentially the same</p>

<pre><code>def test_input(s):
    if len(s) &lt; 5:
        print("Input should contain at least 5 characters!")
        return False
    if re.search("\\s+", s):
        print("Cannot use blank spaces")
        return False
    return True
</code></pre>

<p>6) Run some code that uses all these methods. </p>

<pre><code>status = input("Press R to register!\n")
if status.lower() == "r":
    register()
</code></pre>

python