Skip to content

Instantly share code, notes, and snippets.

@tusharhero
Last active April 14, 2022 06:09
Show Gist options
  • Save tusharhero/de6adee909be26ab8fb6c93eda1195a7 to your computer and use it in GitHub Desktop.
Save tusharhero/de6adee909be26ab8fb6c93eda1195a7 to your computer and use it in GitHub Desktop.
A script to check if the password is secure. Contains 4 separate functions. Only checks for lower case upper case and numbers but u can also add symbols very easily.
#! /bin/python3
'''
WRITTEN BY TUSHAR MAHARANA @tusharhero.github.io
Took 4 days pls do link me if you use this(highly unlikely)
have fun!
'''
'''
LICENSE: https://tusharhero.mit-license.org/
'''
#A python function to check whether a password is secure.
#It checks for the following criteria: atleast 8 characters , lower case, higher case, and numbers
def lengthchk(s,l): #function to check if the length of the password is atleast 8
l = l - 1
if len(s) >= l:
return 1
else:
return 0
def isit(l,dic):# function to check if it atleast contains 1 character from the string
n = 0 #will be used to looping through the string 'dic'
tt = 0 #will also be used for looping through the string 'dic'
for tt in dic: # checks for the 'tt' th letter
if tt == l: #if equals our input then return 1
return 1
else:
n = n + 1 #using this variable because tt is a string now and we need to convert it to a int so we can continue the next loop
tt = n
return 0
def isstring(s,dic):# function to check to if the string countains any character from the string uses isit()
s = str(s)#just to make sure it's a string
a = 0 # will be xplained when used
l = 0 # will be xplained when used
while l < len(s): #will loop until every charater is used up and l is used to keep track of the characters
a = isit(s[l],dic) # uses the isit() to check if the 'l'th character is a valid character
if a == 1: # if it is then returns 1
return 1
else:# if not just continue
l = l + 1 # keeping track of the character number
return 0 # if it still doesn't return 1 and the loop finishes then it returns 0 because nothing matched
def ispasswd(passwd,l,h,n,length):#combines all the functions to check if a password is valid
if lengthchk(passwd,length) == 1:#check if lenghth is correct
if isstring(passwd,l):#check if l is in the password
if isstring(passwd, h):#check if h is in the password
if isstring(passwd, n):#check if n is in the password
return 1#finally return 1
else:#igonre this confusing code i will fix it in the future
return 0
else:
return 0
else:
return 0
else:
return 0
#driver code
lowercase = 'abcdefghijklmnopqrstuvwxyz'
highercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
num = '1234567890'#string containing all lower letters, all numbers, higher letters
print(ispasswd('Amogussussybaka69', lowercase,highercase,num, 8))
#Archived code.
#funny fails
'''
def ispasswd(passwd,dic,l):#combines all the functions to check if a password is valid
if lengthchk(passwd,l) == 1:#check if lenghth is correct
if isstring(passwd,dic):#check if characters from dic is in the password
return 1
else: #if no
return 0
else:#if not
return 0
def ispasswd(passwd,l,h,n,length):#combines all the functions to check if a password is valid
if lengthchk(passwd,length) == 1:#check if lenghth is correct
if isstring(passwd,l):#check if l is in the password
if isstring(passwd, h):#check if h is in the password
if isstring(passwd, n):#check if n is in the password
return 1#finally return 1
else:#igonre this confusing code i will fix it in the future
return 0
else:
return 0
else:
return 0
else:
return 0
#driver code
l = 'abcdefghijklmnopqrstuvwxyz' #string containing all lower letters
h = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' #string containing all higher letters
n = '1234567890'#string containing all higher letters letters
print(ispasswd('12345Ba', l, h, n, 8))
def islower(l):
low = 'abcdefghijklmnopqrstuvwxyz'
a = 0
b = 0
while b == 0:
if l == low[b:]:
a = 1
else:
a = 0
b = b + 1
return 1
#'''
'''
def islower(l):
low = 'abcdefghijklmnopqrstuvwxyz'
for l in low[:1]:
return 1
else:
return 0
#'''
@tusharhero
Copy link
Author

I fixed that problem

@biologyscience
Copy link

biologyscience commented Mar 5, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment