Python Forum

Full Version: Symbols Distinguished From Letters?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm creating a password score program, everything seems to be fine until you enter a password with only symbols. It comes out saying that both upper and lower case letters were used. I need a way to distinguish symbols from upper and lower case letters.

#This program allows the user to see how good the security of his password is based on a point system.
pts = 0

print ("Hello! Welcome to the Password Score Calculator!")

name = input ("What is your name? ")

PW1 = input ("What is your password? ")

PW2 = input ("Please type it again to secure a match. ")

while PW2 != PW1:
    PW1 = input ("Unfortunately,they did not match. Please re-enter your password. ")

    PW2 = input ("Please type it again to secure a match. ")
if PW2 == PW1:
    print ("Secured.")

if len(PW1) >= 8:
    print ("+5 Points")
    pts += 5

if PW1.isupper():
    print ("Please use lowercase and uppercase letters.")
elif PW1.islower():
    print ("Please use lowercase and uppercase letters.")
else:
    print ("+10 Points")
    pts += 10

import re

if any (PW1.isdigit()for PW1 in PW1):
    print ("+10 Points")
    pts += 10

symbols = "~`!@#$%^&*()/_-+={}[]:>;',</?*-+"

contains_symbol = False
for symbols in symbols:
    if symbols in PW1:
        contains_symbol = True
        pts += 5
        print ("+5 Points")
        break
Yeh I need help too!
(Apr-05-2017, 10:50 AM)Ollie Wrote: [ -> ]Yeh I need help too!

nice
>>> from string import ascii_uppercase, ascii_lowercase, punctuation

>>> chars = (ascii_uppercase, ascii_lowercase, punctuation)

>>> def passchk(pw, char_set):
...     pw_len = len(pw)
...     result = 0
...     passwd = set(pw)
...     for chs in char_set:
...         if set(chs) & passwd:
...             result += 10
...         if set(chs) & passwd:
...             result += 10
...         if set(chs) & passwd:
...             result += 10
...         if pw_len >= 15: # 8 symbol password is considered weak
...             result += 5
...         return result

>>> passchk("01;waIInfs*", chars)
30
In the if statements is used a set intersection to check if there are common symbols between the character set and the password. Both are converted to set before that.