top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python Program to Check the Validity of Password

Writer's picture: Alberta JohnsonAlberta Johnson

The above picture gives an idea of what this blog is about.

This blog will discuss how to check the validity of passwords.

A password, sometimes called a passcode, is secret data, typically a string of characters, usually used to confirm a user's identity.


Now let's consider a simple app, written in python language to vheck the validity of passwords.


Primary conditions for password validation :


Minimum 8 characters.

The alphabets must be between [a-z]

At least one alphabet should be of Upper Case [A-Z]

At least 1 number or digit between [0-9].

At least 1 character from [ _ or @ or $ ].


Input : R@m@_f0rtu9e$

Output : Valid Password

Input : Rama_fortune$ Output : Invalid Password

Explanation: Number is missing

Input : Rama#fortu9e Output : Invalid Password Explanation: Must consist from _ or @ or $


Now let's write some codes to check if our password is valid;


password = "R@m@_f0rtu9e$"

is_valid = True
reason = ''

while True:  
    if (len(password)<8):
        is_valid = False
        reason = 'The length of the password is not up to 9 characters'
        break
    elif not re.search("[a-z]", password):
        is_valid = False
        reason = 'There is no lower case alphabet in the password'
        break
    elif not re.search("[A-Z]", password):
        is_valid = False
        reason = 'There is no upper case alphabet in the password'
        break
    elif not re.search("[0-9]", password):
        is_valid = False
        reason = 'There is no digit in the password'
        break
    elif not re.search("[_@$]", password):
        is_valid = False
        reason = 'The password requires atleast one symbol'
        break
    elif re.search("\s", password):
        is_valid = False
        reason = 'The password contains a whitespace'
        break
    else:
        break
  

if is_valid is False:
    print("{} , therefore it's invalid".format(reason))
else:
    print('The password {} is valid'.format(password))

Output :

The password R@m@_f0rtu9e$ is valid

Conclusion

Hurray!!, as seen our password is valid. The above approach is used to check the validity of a password.

0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page