-
Notifications
You must be signed in to change notification settings - Fork 43
/
util.py
executable file
·37 lines (26 loc) · 863 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import hashlib
from flask import session
def hash_password(pwd):
"""
:param pwd: input password
:return: return hash md5 password
"""
from crysadm import app
return hashlib.md5(str("%s%s" % (app.config.get("PASSWORD_PREFIX"), pwd)).encode('utf-8')).hexdigest()
def md5(s):
import hashlib
return hashlib.md5(s.encode('utf-8')).hexdigest().lower()
def sha1(s):
import hashlib
return hashlib.sha1(s.encode('utf-8')).hexdigest().lower()
def get_message():
err_msg = None
if session.get('error_message') is not None:
err_msg = session.get('error_message')
session['error_message'] = None
return err_msg
def set_message(message, type='error'):
if type == 'error':
session['error_message'] = message
elif type == 'info':
session['info_message'] = message