完成弱密码的服务端检测。

pull/105/head
Apex Liu 2017-11-18 01:20:27 +08:00
parent 58b2192753
commit e73b7c5f6b
5 changed files with 33 additions and 8 deletions

View File

@ -76,7 +76,7 @@ $app.on_init = function (cb_stack) {
function (ret) {
if (ret.code === TPE_OK) {
g_header = ret.data;
console.log('header', g_header);
// console.log('header', g_header);
$('#recorder-info').html(tp_format_datetime(g_header.start) + ': ' + g_header.user_name + '@' + g_header.client_ip + ' 访问 ' + g_header.account + '@' + g_header.conn_ip + ':' + g_header.conn_port);
@ -161,7 +161,7 @@ $app.on_init = function (cb_stack) {
pause();
});
$app.dom.progress.mouseup(function () {
console.log(g_current_time);
// console.log(g_current_time);
setTimeout(function () {
init();
}, 100);

View File

@ -304,8 +304,5 @@ function tp_check_strong_password(p) {
s |= 8;
}
if((s&1) && (s&2) && (s&4))
return true;
else
return false;
return !!((s & 1) && (s & 2) && (s & 4));
}

View File

@ -72,6 +72,7 @@ $app.on_init = function (cb_stack) {
if (event.which === 13) {
$app.on_set_new_password();
} else {
$app.hide_op_box();
$('[data-toggle="popover"]').popover('hide');
}
});
@ -231,7 +232,7 @@ $app.on_set_new_password = function () {
if ($app.options.force_strong) {
if (!tp_check_strong_password(str_password)) {
$app.show_op_box('error', '抱歉,不能使用弱密码!');
$app.show_op_box('error', tp_error_msg(TPE_FAILED, '抱歉,不能使用弱密码!'));
$app.dom.set_password.input_password.attr('data-content', "请设置强密码至少8位必须包含大写字母、小写字母以及数字").focus().popover('show');
return;
}

View File

@ -195,6 +195,28 @@ def tp_md5file(file_name):
return m.hexdigest()
def tp_check_strong_password(p):
s = 0
if len(p) < 8:
return False
for i in range(len(p)):
c = ord(p[i])
if 48 <= c <= 57: # 数字
s |= 1
elif 65 <= c <= 90: # 大写字母
s |= 2
elif 97 <= c <= 122: # 小写字母
s |= 4
else:
s |= 8
if (s & 1) and (s & 2) and (s & 4):
return True
else:
return False
class UniqueId:
def __init__(self):
import builtins
@ -215,4 +237,3 @@ def tp_unique_id():
if '__tp_unique_id__' not in builtins.__dict__:
builtins.__dict__['__tp_unique_id__'] = UniqueId()
return builtins.__dict__['__tp_unique_id__'].generate()

View File

@ -12,6 +12,7 @@ from app.base import mail
from app.model import user
from app.model import group
from app.logic.auth.password import tp_password_generate_secret
from app.base.utils import tp_check_strong_password
import tornado.gen
from app.base.logger import *
from app.base.controller import TPBaseHandler, TPBaseJsonHandler
@ -537,6 +538,11 @@ class DoResetPasswordHandler(TPBaseJsonHandler):
except:
return self.write_json(TPE_PARAM)
# 根据需要进行弱密码检测
if get_cfg().sys.password.force_strong:
if not tp_check_strong_password(password):
return self.write_json(TPE_FAILED, '抱歉,不能使用弱密码!')
err, user_id = user.check_reset_token(token)
if err != TPE_OK:
return self.write_json(err)