I wrote my first python application. I know Wordpress, SQL and other stuff I have used has limitations on special characters. Does python use any special characters? This application stops if you fail a section of the tests. I was taught to code this way. Why continue wasting computer cycles, if failure was reached.
It checks your password for the following criteria.
# This program will verify your password is the following criteria
# 2 or more lowercase consonants
# 2 or more lowercase vowels
# 2 or more upper case consonants
# 2 or more upper case vowels
# 2 or more numbers
# minimum of 12 characters
from typing import List
The code is:
# !/usr/bin/python
# This program will verify your password is the following criteria
# 2 or more lowercase consonants
# 2 or more lowercase vowels
# 2 or more upper case consonants
# 2 or more upper case vowels
# 2 or more numbers
# minimum of 12 characters
from typing import List
def main():
# creates arrays of lowercase consonants and uppercase consonants
lower_con = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y',
'z'];
lower_con
upper_con = [element.upper() for element in lower_con];
upper_con
# creates arrays of lowercase vowels and uppercase vowels
lower_vowel = ['a', 'e', 'i', 'o', 'u'];
lower_vowel
upper_vowel = [element.upper() for element in lower_vowel];
upper_vowel
# array of integers
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
# array of special characters
special_char = ['`', '~', '!', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '+', ':', ';', '?', '@', '<', '>',
'_', '/', '|']
pass_test: List[str] = [
'ShortTest77',
'CorrectSize12',
'ThreeeRepeating',
'UPPERCASETESt12',
'UppercaseTest12',
'UppErcaseTest12',
'UppErcaseTest12',
'UppErcASeTests2',
'UpPercAsETest34',
'Up%PercAsETest34',
'Up%PercAsE#Test34']
print(upper_con)
print(lower_vowel)
print(upper_vowel)
print(numbers)
print(special_char)
print(pass_test)
print(' ')
print('now comes the fun stuff')
# first thing check the password is longer than 12 characters
# if shorter, you don't need to keep testing
for a in pass_test:
# is the password 12 characters or longer
print(" ")
if len(a) < 12:
pass_testTF = "false"
print(a, " ", "FAILED: Password is too short")
else:
print(a, " ", "PASSED: password is 12 characters or longer")
pass_testTF = "true"
# Next test is 3 duplicate characters
import time
if pass_testTF == "true":
lengthofpw = len(a)
loopcount = lengthofpw - 2
c = 0
while c < loopcount:
if a[c] == a[c + 1] == a[c + 2]:
pass_testTF = "false"
c += 1
if pass_testTF == "true":
print(a, " ", "PASSED: Does not have 3 repeating character")
else:
print(a, " ", "FAILED: has 3 repeating characters")
# does it contain 2 or more lower case letters
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
lower_con_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 20:
if a[c] == lower_con[cc]:
lower_con_count += 1
cc += 1
c += 1
if lower_con_count >= 2:
print(a, " ", "PASSED: It has at least 2 lower case consonants")
else:
print(a, " ", "FAILED: It has less than 2 lower case consonants")
pass_testTF = "false"
# does it contain 2 or more upper case consonants
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
upper_con_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 20:
if a[c] == upper_con[cc]:
upper_con_count += 1
cc += 1
c += 1
if upper_con_count >= 2:
print(a, " ", "PASSED: It has at least 2 upper case consonants")
else:
print(a, " ", "FAILED: It has less than 2 upper case consonants")
pass_testTF = "false"
# does it contain 2 or more uppercase vowels
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
upper_vowel_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 4:
if a[c] == upper_vowel[cc]:
upper_vowel_count += 1
cc += 1
c += 1
if upper_vowel_count >= 2:
print(a, " ", "PASSED: It has at least 2 uppercase vowels")
else:
print(a, " ", "FAILED: It has less than 2 uppercase vowels")
pass_testTF = "false"
# does it contain 2 or more lowercase vowels
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
lower_vowel_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 4:
if a[c] == lower_vowel[cc]:
lower_vowel_count += 1
cc += 1
c += 1
if lower_vowel_count >= 2:
print(a, " ", "PASSED: It has at least 2 lowercase vowels")
else:
print(a, " ", "FAILED: It has less than 2 lowercase vowels")
pass_testTF = "false"
# does it contain 2 or more numbers
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
number_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 9:
if a[c] == numbers[cc]:
number_count += 1
cc += 1
c += 1
if number_count >= 2:
print(a, " ", "PASSED: It has at least than 2 numbers")
else:
print(a, " ", "FAILED: It has less than 2 numbers")
pass_testTF = "false"
# does it contain 2 or more special characters
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
spec_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 9:
if a[c] == special_char[cc]:
spec_count += 1
cc += 1
c += 1
if spec_count >= 2:
print(a, " ", "PASSED: It has at least than 2 special characters")
else:
print(a, " ", "FAILED: It has less thn 2 special characters")
pass_testTF = "false"
if __name__ == "__main__":
main()
# !/usr/bin/python
# This program will verify your password is the following criteria
# 2 or more lowercase consonants
# 2 or more lowercase vowels
# 2 or more upper case consonants
# 2 or more upper case vowels
# 2 or more numbers
# minimum of 12 characters
from typing import List
def main():
# creates arrays of lowercase consonants and uppercase consonants
lower_con = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y',
'z'];
lower_con
upper_con = [element.upper() for element in lower_con];
upper_con
# creates arrays of lowercase vowels and uppercase vowels
lower_vowel = ['a', 'e', 'i', 'o', 'u'];
lower_vowel
upper_vowel = [element.upper() for element in lower_vowel];
upper_vowel
# array of integers
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
# array of special characters
special_char = ['`', '~', '!', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '+', ':', ';', '?', '@', '<', '>',
'_', '/', '|']
pass_test: List[str] = [
'ShortTest77',
'CorrectSize12',
'ThreeeRepeating',
'UPPERCASETESt12',
'UppercaseTest12',
'UppErcaseTest12',
'UppErcaseTest12',
'UppErcASeTests2',
'UpPercAsETest34',
'Up%PercAsETest34',
'Up%PercAsE#Test34']
print(upper_con)
print(lower_vowel)
print(upper_vowel)
print(numbers)
print(special_char)
print(pass_test)
print(' ')
print('now comes the fun stuff')
# first thing check the password is longer than 12 characters
# if shorter, you don't need to keep testing
for a in pass_test:
# is the password 12 characters or longer
print(" ")
if len(a) < 12:
pass_testTF = "false"
print(a, " ", "FAILED: Password is too short")
else:
print(a, " ", "PASSED: password is 12 characters or longer")
pass_testTF = "true"
# Next test is 3 duplicate characters
import time
if pass_testTF == "true":
lengthofpw = len(a)
loopcount = lengthofpw - 2
c = 0
while c < loopcount:
if a[c] == a[c + 1] == a[c + 2]:
pass_testTF = "false"
c += 1
if pass_testTF == "true":
print(a, " ", "PASSED: Does not have 3 repeating character")
else:
print(a, " ", "FAILED: has 3 repeating characters")
# does it contain 2 or more lower case letters
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
lower_con_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 20:
if a[c] == lower_con[cc]:
lower_con_count += 1
cc += 1
c += 1
if lower_con_count >= 2:
print(a, " ", "PASSED: It has at least 2 lower case consonants")
else:
print(a, " ", "FAILED: It has less than 2 lower case consonants")
pass_testTF = "false"
# does it contain 2 or more upper case consonants
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
upper_con_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 20:
if a[c] == upper_con[cc]:
upper_con_count += 1
cc += 1
c += 1
if upper_con_count >= 2:
print(a, " ", "PASSED: It has at least 2 upper case consonants")
else:
print(a, " ", "FAILED: It has less than 2 upper case consonants")
pass_testTF = "false"
# does it contain 2 or more uppercase vowels
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
upper_vowel_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 4:
if a[c] == upper_vowel[cc]:
upper_vowel_count += 1
cc += 1
c += 1
if upper_vowel_count >= 2:
print(a, " ", "PASSED: It has at least 2 uppercase vowels")
else:
print(a, " ", "FAILED: It has less than 2 uppercase vowels")
pass_testTF = "false"
# does it contain 2 or more lowercase vowels
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
lower_vowel_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 4:
if a[c] == lower_vowel[cc]:
lower_vowel_count += 1
cc += 1
c += 1
if lower_vowel_count >= 2:
print(a, " ", "PASSED: It has at least 2 lowercase vowels")
else:
print(a, " ", "FAILED: It has less than 2 lowercase vowels")
pass_testTF = "false"
# does it contain 2 or more numbers
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
number_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 9:
if a[c] == numbers[cc]:
number_count += 1
cc += 1
c += 1
if number_count >= 2:
print(a, " ", "PASSED: It has at least than 2 numbers")
else:
print(a, " ", "FAILED: It has less than 2 numbers")
pass_testTF = "false"
# does it contain 2 or more special characters
# Outside loop is the letters of test-Pass
if pass_testTF == "true":
c = 0
spec_count = 0
while c < lengthofpw:
# inside loop is the lower_con array
cc = 0
while cc < 9:
if a[c] == special_char[cc]:
spec_count += 1
cc += 1
c += 1
if spec_count >= 2:
print(a, " ", "PASSED: It has at least than 2 special characters")
else:
print(a, " ", "FAILED: It has less thn 2 special characters")
pass_testTF = "false"
if __name__ == "__main__":
main()
Output:
/home/michael/PycharmProjects/firstproj/venv/bin/python /home/michael/PycharmProjects/firstproj/arrays.py
['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']
['a', 'e', 'i', 'o', 'u']
['A', 'E', 'I', 'O', 'U']
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
['`', '~', '!', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', '+', ':', ';', '?', '@', '<', '>', '_', '/', '|']
['ShortTest77', 'CorrectSize12', 'ThreeeRepeating', 'UPPERCASETESt12', 'UppercaseTest12', 'UppErcaseTest12', 'UppErcaseTest12', 'UppErcASeTests2', 'UpPercAsETest34', 'Up%PercAsETest34', 'Up%PercAsE#Test34']
now comes the fun stuff
ShortTest77 FAILED: Password is too short
CorrectSize12 PASSED: password is 12 characters or longer
CorrectSize12 PASSED: Does not have 3 repeating character
CorrectSize12 PASSED: It has at least 2 lower case consonants
CorrectSize12 PASSED: It has at least 2 upper case consonants
CorrectSize12 FAILED: It has less than 2 uppercase vowels
ThreeeRepeating PASSED: password is 12 characters or longer
ThreeeRepeating FAILED: has 3 repeating characters
UPPERCASETESt12 PASSED: password is 12 characters or longer
UPPERCASETESt12 PASSED: Does not have 3 repeating character
UPPERCASETESt12 FAILED: It has less than 2 lower case consonants
UppercaseTest12 PASSED: password is 12 characters or longer
UppercaseTest12 PASSED: Does not have 3 repeating character
UppercaseTest12 PASSED: It has at least 2 lower case consonants
UppercaseTest12 FAILED: It has less than 2 upper case consonants
UppErcaseTest12 PASSED: password is 12 characters or longer
UppErcaseTest12 PASSED: Does not have 3 repeating character
UppErcaseTest12 PASSED: It has at least 2 lower case consonants
UppErcaseTest12 FAILED: It has less than 2 upper case consonants
UppErcaseTest12 PASSED: password is 12 characters or longer
UppErcaseTest12 PASSED: Does not have 3 repeating character
UppErcaseTest12 PASSED: It has at least 2 lower case consonants
UppErcaseTest12 FAILED: It has less than 2 upper case consonants
UppErcASeTests2 PASSED: password is 12 characters or longer
UppErcASeTests2 PASSED: Does not have 3 repeating character
UppErcASeTests2 PASSED: It has at least 2 lower case consonants
UppErcASeTests2 PASSED: It has at least 2 upper case consonants
UppErcASeTests2 PASSED: It has at least 2 uppercase vowels
UppErcASeTests2 PASSED: It has at least 2 lowercase vowels
UppErcASeTests2 FAILED: It has less than 2 numbers
UpPercAsETest34 PASSED: password is 12 characters or longer
UpPercAsETest34 PASSED: Does not have 3 repeating character
UpPercAsETest34 PASSED: It has at least 2 lower case consonants
UpPercAsETest34 PASSED: It has at least 2 upper case consonants
UpPercAsETest34 PASSED: It has at least 2 uppercase vowels
UpPercAsETest34 PASSED: It has at least 2 lowercase vowels
UpPercAsETest34 PASSED: It has at least than 2 numbers
UpPercAsETest34 FAILED: It has less thn 2 special characters
Up%PercAsETest34 PASSED: password is 12 characters or longer
Up%PercAsETest34 PASSED: Does not have 3 repeating character
Up%PercAsETest34 PASSED: It has at least 2 lower case consonants
Up%PercAsETest34 PASSED: It has at least 2 upper case consonants
Up%PercAsETest34 PASSED: It has at least 2 uppercase vowels
Up%PercAsETest34 PASSED: It has at least 2 lowercase vowels
Up%PercAsETest34 PASSED: It has at least than 2 numbers
Up%PercAsETest34 FAILED: It has less thn 2 special characters
Up%PercAsE#Test34 PASSED: password is 12 characters or longer
Up%PercAsE#Test34 PASSED: Does not have 3 repeating character
Up%PercAsE#Test34 PASSED: It has at least 2 lower case consonants
Up%PercAsE#Test34 PASSED: It has at least 2 upper case consonants
Up%PercAsE#Test34 PASSED: It has at least 2 uppercase vowels
Up%PercAsE#Test34 PASSED: It has at least 2 lowercase vowels
Up%PercAsE#Test34 PASSED: It has at least than 2 numbers
Up%PercAsE#Test34 PASSED: It has at least than 2 special characters
Process finished with exit code 0