diff options
author | David Lu <david.lu@hotmail.com> | 2016-07-06 18:54:54 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-07-06 14:54:54 -0800 |
commit | 683f7133190aa350cdd1ea2608c90fe5f47b35cd (patch) | |
tree | 3f1bcc19d3bc1a7dedd407c266ea63cdda5ed9c9 /webapp/utils/utils.jsx | |
parent | 0c3c52b8d3a3503c35481a287ba27f626749503a (diff) | |
download | chat-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/utils.jsx')
-rw-r--r-- | webapp/utils/utils.jsx | 68 |
1 files changed, 67 insertions, 1 deletions
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; +} |