﻿ Python check password strength and get suggestions

Python Cyber Security - Check password strength and get suggestions

Python Cyber Security: Exercise-7 with Solution

Write a Python program that creates a password strength meter. The program should prompt the user to enter a password and check its strength based on criteria such as length, complexity, and randomness. Afterwards, the program should provide suggestions for improving the password's strength.

The highest strength password that meets the criteria specified in the program will receive a score of 5.

(e.g. at least 8 characters, contains both uppercase and lowercase letters, and at least one number and one special character).

Sample Solution:

Python Code:

``````import re

score = 0
suggestions = []

# check length
score += 1
else:
suggestions.append("Password should be at least 8 characters long")

# check for uppercase letter
score += 1
else:
suggestions.append("Password should contain at least one uppercase letter")

# check for lowercase letter
score += 1
else:
suggestions.append("Password should contain at least one lowercase letter")

# check for numeric digit
score += 1
else:
suggestions.append("Password should contain at least one numeric digit")

# check for special character
score += 1
else:
suggestions.append("Password should contain at least one special character ([email protected]#\$%^&*(),.?\":{}|<>)")

return score, suggestions
```
```

Sample Output:

```Input a password: Akoiuw3^*([email protected]
(5, [])

(4, ['Password should contain at least one lowercase letter'])

(4, ['Password should contain at least one special character ([email protected]#\$%^&*(),.?":{}|<>)'])

(2, ['Password should be at least 8 characters long', 'Password should contain at least one numeric digit', 'Password should contain at least one special character ([email protected]#\$%^&*(),.?":{}|<>)'])
```

Flowchart:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

Python: Tips of the Day

Decapitalizes the first letter of a string:

Example:

```def tips_decapitalize(s, upper_rest=False):
return s[:1].lower() + (s[1:].upper() if upper_rest else s[1:])
print(tips_decapitalize('PythonTips'))
print(tips_decapitalize('PythonTips', True))
```

Output:

```pythonTips
pYTHONTIPS
```

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook