Python Forum
Symbols Distinguished From Letters?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Symbols Distinguished From Letters?
#1
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
Reply
#2
Yeh I need help too!
Reply
#3
(Apr-05-2017, 10:50 AM)Ollie Wrote: Yeh I need help too!

nice
Reply
#4
>>> 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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python script that deletes symbols in plain text nzcan 3 686 Sep-05-2023, 04:03 PM
Last Post: deanhystad
  cyrillic symbols in tables in reportlab. hiroz 5 11,397 Sep-10-2020, 04:57 AM
Last Post: bradmalcom
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,040 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  Replacing symbols by " Tiihu 1 1,855 Feb-13-2020, 09:27 PM
Last Post: Larz60+
  How do I delete symbols in a list of strings? Than999 1 2,276 Nov-16-2019, 09:37 PM
Last Post: ibreeden
  Python symbols AND letters gullidog 1 3,488 Apr-05-2017, 10:13 PM
Last Post: ichabod801
  Strings containing both symbols and letters gullidog 13 8,184 Apr-05-2017, 12:27 PM
Last Post: ankit
  Symbols in a String MeMeBigBoy 4 4,269 Apr-05-2017, 11:21 AM
Last Post: garfield
  How to get pyhton to identify symbols in a string MemeLord15 4 4,317 Apr-05-2017, 11:14 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020