PLT-1465 Added password requirements (#3489)
* Added password requirements * added tweaks * fixed error code * removed http.StatusNotAcceptable
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
0c3c52b8d3
Коммит
683f713319
@@ -758,7 +758,7 @@ export default {
|
||||
MAX_USERNAME_LENGTH: 22,
|
||||
MAX_NICKNAME_LENGTH: 22,
|
||||
MIN_PASSWORD_LENGTH: 5,
|
||||
MAX_PASSWORD_LENGTH: 50,
|
||||
MAX_PASSWORD_LENGTH: 64,
|
||||
MIN_TRIGGER_LENGTH: 1,
|
||||
MAX_TRIGGER_LENGTH: 128,
|
||||
TIME_SINCE_UPDATE_INTERVAL: 30000,
|
||||
|
||||
@@ -14,10 +14,13 @@ import * as AsyncClient from './async_client.jsx';
|
||||
import Client from './web_client.jsx';
|
||||
|
||||
import {browserHistory} from 'react-router/es6';
|
||||
import {FormattedMessage} from 'react-intl';
|
||||
|
||||
import icon50 from 'images/icon50x50.png';
|
||||
import bing from 'images/bing.mp3';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
export function isEmail(email) {
|
||||
// writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378)
|
||||
// so we just do a simple check and rely on a verification email to tell if it's a real address
|
||||
@@ -1366,4 +1369,67 @@ export function canCreateCustomEmoji(user) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function isValidPassword(password) {
|
||||
let errorMsg = '';
|
||||
let errorId = 'user.settings.security.passwordError';
|
||||
let error = false;
|
||||
let minimumLength = Constants.MIN_PASSWORD_LENGTH;
|
||||
|
||||
if (global.window.mm_config.BuildEnterpriseReady === 'true' && global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.PasswordRequirements === 'true') {
|
||||
if (password.length < parseInt(global.window.mm_config.PasswordMinimumLength, 10) || password.length > Constants.MAX_PASSWORD_LENGTH) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (global.window.mm_config.PasswordRequireLowercase === 'true') {
|
||||
if (!password.match(/[a-z]/)) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
errorId = errorId + 'Lowercase';
|
||||
}
|
||||
|
||||
if (global.window.mm_config.PasswordRequireUppercase === 'true') {
|
||||
if (!password.match(/[0-9]/)) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
errorId = errorId + 'Uppercase';
|
||||
}
|
||||
|
||||
if (global.window.mm_config.PasswordRequireNumber === 'true') {
|
||||
if (!password.match(/[A-Z]/)) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
errorId = errorId + 'Number';
|
||||
}
|
||||
|
||||
if (global.window.mm_config.PasswordRequireSymbol === 'true') {
|
||||
if (!password.match(/[ !"\\#$%&'()*+,-./:;<=>?@[\]^_`|~]/)) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
errorId = errorId + 'Symbol';
|
||||
}
|
||||
|
||||
minimumLength = global.window.mm_config.PasswordMinimumLength;
|
||||
} else if (password.length < Constants.MIN_PASSWORD_LENGTH) {
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
errorMsg = (
|
||||
<FormattedMessage
|
||||
id={errorId}
|
||||
default='Your password must be at least {min} characters.'
|
||||
values={{
|
||||
min: minimumLength
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user