提交 14ac4bb4 编写于 作者: C chenyanpan

check latin1 character set in function password_encode_check

https://gitee.com/openeuler/openEuler-Advisor/pulls/105#note_3175442
上级 f48b0271
......@@ -8,6 +8,32 @@ import re
from werkzeug.security import generate_password_hash
def usage():
""" usage """
print(
"""usage: generate_password PASSWORD
Requirements:
1. PASSWORD must be within the 'latin1' character set
2. PASSWORD strength require:
6 characters or more
at least 1 digit [0-9]
at least 1 alphabet [a-z]
at least 1 alphabet of Upper Case [A-Z]
at least 1 special character from [~!@#%^*_+=-]
"""
)
def password_encode_check(password):
""" check if password within the latin1 character set """
try:
password.encode("latin1")
except UnicodeEncodeError as err:
return str(err)
return None
def password_strength_check(password):
"""
Verify the strength of 'password'
......@@ -44,40 +70,15 @@ def password_strength_check(password):
}
def usage():
""" usage """
print(
"""usage: generate_password PASSWORD
Requirements:
1. PASSWORD must be within the 'latin1' character set
2. PASSWORD strength require:
6 characters or more
at least 1 digit [0-9]
at least 1 alphabet [a-z]
at least 1 alphabet of Upper Case [A-Z]
at least 1 special character from [~!@#%^*_+=-]
"""
)
def latin1_encode(text):
""" latin1 encode """
try:
text.encode("latin1")
except UnicodeEncodeError as err:
return str(err)
return None
if __name__ == "__main__":
if len(sys.argv) != 2:
usage()
sys.exit(1)
password_ = sys.argv[1]
err = latin1_encode(password_)
if err:
ret = password_encode_check(password_)
if ret:
usage()
print("PASSWORD: only latin1 character set are allowed")
sys.exit(1)
......@@ -85,7 +86,6 @@ if __name__ == "__main__":
ret = password_strength_check(password_)
if not ret['ok']:
usage()
print("Password strength is not satisfied:")
for item in ret['error']:
if ret['error'][item]:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册