I'm trying to make a password checker in python. Is there a way of preventing a user from entering 2 consecutive lower case characters without using regex? Would prefer the program to take input from the user. Thanks
Yes, you can prevent user from entering 2 consecutive lower case characters without using regex.
Traverse the password string given by user by using for loop in range from 1 to length of password string. You can define password_checker() function like :
def password_checker(password):
val= True
for x in range(1, len(password)):
if ord(password[x-1])>=97 and ord(password[x]) <=122:
print("No 2 consecutive lowercase alphabet are allowed)
val= False
break
""" you can add more conditions here"""
if(val):
return val
#Main method
def main():
password= input()
if(password_checker(password)):
print("Valid Password")
else:
print("Invalid Password")
# Driver code
if __name__ == '__main__':
main()
Get Answers For Free
Most questions answered within 1 hours.