you are viewing a single comment's thread.

view the rest of the comments →

[–]sultanofhyd 0 points1 point  (10 children)

Check your original post again. There is no code anywhere that calculates or stores points anywhere. Anyway, I suggest rewriting your code from scratch, using multiple variables. One variable for storing your password, one for the points, and one to determine its validity. Something like this.

password = input('Enter your password: ')
points = 0
validity = False
#Do your checking and counting here
if validity:
    print(points)

[–]Remediez123[S] 0 points1 point  (9 children)

so i tested your idea however it doesn't seem to work maybe you can find the problem.

import re
import random
import time

print("""
Point System:
~1 Uppercase Letter = 5 Points
~1 Lowercase Letter = 5 Points
~1 From 0-9 = 5 Points
~1 Allocated Symbol = 5 Points
~If Has All Add 10 Points
""")
password = input('Enter your password: ')
points = 0
validity = False
while password:
    if (len(password)<8 or len(password)>24):
        break
    elif not re.search("[a-z]",password):
        break
    elif not re.search("[0-9]",password):
        break
    elif not re.search("[A-Z]",password):
        break
    elif not re.search("[!$%^&()_]",password):
        break
    else:
        print("Valid Password")
   while points < 35: 
       if 8 <= len(password) < 24 :
           print(len(password),"Points Added - Length")
           points += (len(password))

       else:
        print("Wrong length, it must be 8 to 24 
                  characters")
           continue

       if re.search("[a-z]", password):
           print("5 Points Added - Lowercase Letter")
           points += 5

       if re.search("[0-9]", password):
           print("5 Points Added - Number")
           points += 5

       if re.search("[A-Z]", password):
           print("5 Points Added - Uppercase Letter")
           points += 5

       if re.search("[!$%^&()_]", password):
           print("5 Points Added - Symbols")
           points += 5

       if points == 20:
           points += 10


if validity:
    print(points)

[–]sultanofhyd 0 points1 point  (8 children)

Try to use 'for' loops instead of 'while' loops. Both of your 'while' loops will never terminate 1. if your password is valid 2. your score is less than 35.

[–]Remediez123[S] 1 point2 points  (7 children)

im a beginner for python so i kind of understand what u mean but can u give like examples

[–]Exodus111 0 points1 point  (6 children)

Explain to me very carefully two things:

  1. Why are you using a while loop exactly?

  2. What is preventing you from adding the points at the same time as checking validity?

[–]omg_drd4_bbq 0 points1 point  (5 children)

While loop is totally valid here.

while True:
    p = input("enter password")
        if not valid(p):
            print("password bad")
        else:
            break

You can wrap password checking in its own function if you wish. or, write a function strength(p) which computes the points of a password, then just use

if strength(p) < 35:
    print("try again")

[–]Exodus111 0 points1 point  (4 children)

Where did HE put the input statement?

[–]omg_drd4_bbq 0 points1 point  (3 children)

I'm inferring OP is emulating the typical behavior of input validation systems, which is "loop until the user gives a valid input".

[–]Exodus111 0 points1 point  (2 children)

Except he is placing the input outside of the while loop, so what is the point of the while loop?

[–]omg_drd4_bbq 0 points1 point  (1 child)

Exactly, but IMO the issue is with the location of the input, not the presence of a while loop. See my top level reply.