Skip to main content

Posts

Showing posts from January, 2015

Password Strength Checker

How can I check if my password secure enough?

These are the conditions:

1. Must be at least 8 character long.
2. Must contain at least one digit.
3. Must contain at least one alphabet.
4. Must contain at least one Uppercase
5. Must contain at least one Lowercase
6. Must contain at least one special character among "!@#$%^&*()?".

This could be your answer:

===========================================
password = raw_input('Enter the password ')
special = '!@#$%^&*()?'
if len(password) >= 8 and not password.islower() and not password.isupper() and not password.isalpha() and not password.isdigit() and any((c in special) for c in password):
    print 'password is strong'
else:
    print 'Weak Password'

==========================================

Explanation:

1. islower is False means at least one uppercase. 
2. isupper is False means at least one lowercase.
3. isdigit is False means at least one alphabet.
4. isalpha is False means at least one digit.
5. any((c…

Remove Unique Elemets From a List

Suppose you have to remove unique elements from a list. This is what you can do:

digits = [ 1, 2, 1, 4, 5, 3, 4, 2, 3, 7, 8 ]
copy = []
for x in digits:
    if digits.count(x) == 1:
        copy.append(x)

for y in copy:
    digits.remove(y)
print digits

===========================================================
Explanation:
1. Why two loops?
Never remove elements from a list while iterating the same list. This will give unexpected results. Better make a new list, add all the elements to be removed in the new list. Then remove the elements in this new from original list. That's exactly what I have done.