Change language

#10 Python Validate Password using RegEx

#10 Python Validate Password using RegEx

in this python video we will learn about validate password using regex consider our password should be 6 character long should contain at least one upper case letter, one digit and one special symbol thats how our password looks like.

whenever we want to write regex, we need to import re module.

i will write pattern here i will give raw string as empty string this precompiles python regex regex object which we can use later in our program i will take while loop, while true i will take password as input from the user enter the password i will check whether the password is 6 characters long, if it is less than 6, print a statement telling that password must be 6 character long, if you types password correctly then i will check for special symbol re.search ([email protected]#%&) we have to match with password, if it returns none if the result is none i need to tell user that password must contain atleast one special symbol i will take one more elif we are going to search whether digit is present in our string if this returns none i should write password must contain atlest one digit. i will take one more search method to check upper case letters.

here also if it returns none we need to tell user that you should provide atleast one capital letter.

these things we are going to check i will take one more else if now i will make use of match method, here i am going to write regular expression which contain a-z A-Z and digits from 0-9 and special symbol and we need to verify the length of the password {6} i am going to match with password, so here i will take pattern object, to this object i will give pattern i will make use of one more variable result print password is correct, after that break here else we will take one more print function we will print password invalid.

lets run this, its asking to enter password.

first i will enter only 3 characters, it is telling password must be 6 characters long i will enter 6 character long password now it is telling password must contain atleast one special symbol now it is telling password is correct till now what we were typing password was visible to us , now we will write protected password, so python has built in module called, getpass we need to import that first here instead of input , i need to change getpass.getpass now run this and check what happens, so its asking us to enter password.

i will enter abc it is not echoing anything, what ever i am typing not showing on the screen, but when i run this it is telling password must be 6 characters long, because i entered only 3 characters, now lets try with another use case now it is telling password must contain atleast one special symbol, now i will give ABC#12, now it is telling password is correct.

i hope you are clear with all these concepts.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically