summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorDavid Lu <david.lu@hotmail.com>2016-07-06 18:54:54 -0400
committerCorey Hulen <corey@hulen.com>2016-07-06 14:54:54 -0800
commit683f7133190aa350cdd1ea2608c90fe5f47b35cd (patch)
tree3f1bcc19d3bc1a7dedd407c266ea63cdda5ed9c9 /webapp/utils
parent0c3c52b8d3a3503c35481a287ba27f626749503a (diff)
downloadchat-683f7133190aa350cdd1ea2608c90fe5f47b35cd.tar.gz
chat-683f7133190aa350cdd1ea2608c90fe5f47b35cd.tar.bz2
chat-683f7133190aa350cdd1ea2608c90fe5f47b35cd.zip
PLT-1465 Added password requirements (#3489)
* Added password requirements * added tweaks * fixed error code * removed http.StatusNotAcceptable
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/constants.jsx2
-rw-r--r--webapp/utils/utils.jsx68
2 files changed, 68 insertions, 2 deletions
diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx
index f0cea9e52..52fb23d51 100644
--- a/webapp/utils/constants.jsx
+++ b/webapp/utils/constants.jsx
@@ -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,
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index 1b4b504f2..5f88f5b73 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -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;
-} \ No newline at end of file
+}
+
+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;
+}