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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import AdminSettings from './admin_settings.jsx';
import {FormattedMessage} from 'react-intl';
import SettingsGroup from './settings_group.jsx';
import TextSetting from './text_setting.jsx';
import BooleanSetting from './boolean_setting.jsx';
import Setting from './setting.jsx';
import * as Utils from 'utils/utils.jsx';
import Constants from 'utils/constants.jsx';
import GeneratedSetting from './generated_setting.jsx';
export default class PasswordSettings extends AdminSettings {
constructor(props) {
super(props);
this.getConfigFromState = this.getConfigFromState.bind(this);
this.renderSettings = this.renderSettings.bind(this);
this.getSampleErrorMsg = this.getSampleErrorMsg.bind(this);
this.handlePasswordLengthChange = this.handlePasswordLengthChange.bind(this);
this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
this.state = Object.assign(this.state, {
passwordMinimumLength: props.config.PasswordSettings.MinimumLength,
passwordLowercase: props.config.PasswordSettings.Lowercase,
passwordNumber: props.config.PasswordSettings.Number,
passwordUppercase: props.config.PasswordSettings.Uppercase,
passwordSymbol: props.config.PasswordSettings.Symbol,
maximumLoginAttempts: props.config.ServiceSettings.MaximumLoginAttempts,
enableMultifactorAuthentication: props.config.ServiceSettings.EnableMultifactorAuthentication,
passwordResetSalt: props.config.EmailSettings.PasswordResetSalt
});
// Update sample message from config settings
this.sampleErrorMsg = null;
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.PasswordRequirements === 'true') {
let sampleErrorMsgId = 'user.settings.security.passwordError';
if (props.config.PasswordSettings.Lowercase) {
sampleErrorMsgId = sampleErrorMsgId + 'Lowercase';
}
if (props.config.PasswordSettings.Uppercase) {
sampleErrorMsgId = sampleErrorMsgId + 'Uppercase';
}
if (props.config.PasswordSettings.Number) {
sampleErrorMsgId = sampleErrorMsgId + 'Number';
}
if (props.config.PasswordSettings.Symbol) {
sampleErrorMsgId = sampleErrorMsgId + 'Symbol';
}
this.sampleErrorMsg = (
<FormattedMessage
id={sampleErrorMsgId}
default='Your password must be at least {min} characters.'
values={{
min: (this.state.passwordMinimumLength || Constants.MIN_PASSWORD_LENGTH)
}}
/>
);
}
}
getConfigFromState(config) {
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.PasswordRequirements === 'true') {
config.PasswordSettings.MinimumLength = this.parseIntNonZero(this.state.passwordMinimumLength, Constants.MIN_PASSWORD_LENGTH);
config.PasswordSettings.Lowercase = this.refs.lowercase.checked;
config.PasswordSettings.Uppercase = this.refs.uppercase.checked;
config.PasswordSettings.Number = this.refs.number.checked;
config.PasswordSettings.Symbol = this.refs.symbol.checked;
}
config.ServiceSettings.MaximumLoginAttempts = this.parseIntNonZero(this.state.maximumLoginAttempts);
config.EmailSettings.PasswordResetSalt = this.state.passwordResetSalt;
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.MFA === 'true') {
config.ServiceSettings.EnableMultifactorAuthentication = this.state.enableMultifactorAuthentication;
}
return config;
}
getStateFromConfig(config) {
return {
passwordMinimumLength: config.PasswordSettings.MinimumLength,
passwordLowercase: config.PasswordSettings.Lowercase,
passwordNumber: config.PasswordSettings.Number,
passwordUppercase: config.PasswordSettings.Uppercase,
passwordSymbol: config.PasswordSettings.Symbol,
maximumLoginAttempts: config.ServiceSettings.MaximumLoginAttempts,
enableMultifactorAuthentication: config.ServiceSettings.EnableMultifactorAuthentication,
passwordResetSalt: config.EmailSettings.PasswordResetSalt
};
}
getSampleErrorMsg(minLength) {
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.PasswordRequirements === 'true') {
if (this.props.config.PasswordSettings.MinimumLength > Constants.MAX_PASSWORD_LENGTH || this.props.config.PasswordSettings.MinimumLength < Constants.MIN_PASSWORD_LENGTH) {
return (
<FormattedMessage
id='user.settings.security.passwordMinLength'
default='Invalid minimum length, cannot show preview.'
/>
);
}
let sampleErrorMsgId = 'user.settings.security.passwordError';
if (this.refs.lowercase.checked) {
sampleErrorMsgId = sampleErrorMsgId + 'Lowercase';
}
if (this.refs.uppercase.checked) {
sampleErrorMsgId = sampleErrorMsgId + 'Uppercase';
}
if (this.refs.number.checked) {
sampleErrorMsgId = sampleErrorMsgId + 'Number';
}
if (this.refs.symbol.checked) {
sampleErrorMsgId = sampleErrorMsgId + 'Symbol';
}
return (
<FormattedMessage
id={sampleErrorMsgId}
default='Your password must be at least {min} characters.'
values={{
min: (minLength || Constants.MIN_PASSWORD_LENGTH)
}}
/>
);
}
return null;
}
handlePasswordLengthChange(id, value) {
this.sampleErrorMsg = this.getSampleErrorMsg(value);
this.handleChange(id, value);
}
handleCheckboxChange(id, value) {
this.sampleErrorMsg = this.getSampleErrorMsg(this.state.passwordMinimumLength);
this.handleChange(id, value);
}
renderTitle() {
return (
<h3>
<FormattedMessage
id='admin.security.password'
defaultMessage='Password'
/>
</h3>
);
}
renderSettings() {
let mfaSetting = null;
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.MFA === 'true') {
mfaSetting = (
<BooleanSetting
id='enableMultifactorAuthentication'
label={
<FormattedMessage
id='admin.service.mfaTitle'
defaultMessage='Enable Multi-factor Authentication:'
/>
}
helpText={
<FormattedMessage
id='admin.service.mfaDesc'
defaultMessage='When true, users will be given the option to add multi-factor authentication to their account. They will need a smartphone and an authenticator app such as Google Authenticator.'
/>
}
value={this.state.enableMultifactorAuthentication}
onChange={this.handleChange}
/>
);
}
let passwordSettings = null;
if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.PasswordRequirements === 'true') {
passwordSettings = (
<div>
<TextSetting
id='passwordMinimumLength'
label={
<FormattedMessage
id='admin.password.minimumLength'
defaultMessage='Minimum Password Length:'
/>
}
placeholder={Utils.localizeMessage('admin.password.minimumLengthExample', 'Ex "5"')}
helpText={
<FormattedMessage
id='admin.password.minimumLengthDescription'
defaultMessage='Minimum number of characters required for a valid password. Must be a whole number greater than or equal to {min} and less than or equal to {max}.'
values={{
min: (this.state.passwordMinimumLength || Constants.MIN_PASSWORD_LENGTH),
max: Constants.MAX_PASSWORD_LENGTH
}}
/>
}
value={this.state.passwordMinimumLength}
onChange={this.handlePasswordLengthChange}
/>
<Setting
label={
<FormattedMessage
id='passwordRequirements'
defaultMessage='Password Requirements:'
/>
}
>
<div>
<label className='checkbox-inline'>
<input
type='checkbox'
ref='lowercase'
defaultChecked={this.state.passwordLowercase}
name='admin.password.lowercase'
onChange={this.handleCheckboxChange}
/>
<FormattedMessage
id='admin.password.lowercase'
defaultMessage='At least one lowercase letter'
/>
</label>
</div>
<div>
<label className='checkbox-inline'>
<input
type='checkbox'
ref='uppercase'
defaultChecked={this.state.passwordUppercase}
name='admin.password.uppercase'
onChange={this.handleCheckboxChange}
/>
<FormattedMessage
id='admin.password.uppercase'
defaultMessage='At least one uppercase letter'
/>
</label>
</div>
<div>
<label className='checkbox-inline'>
<input
type='checkbox'
ref='number'
defaultChecked={this.state.passwordNumber}
name='admin.password.number'
onChange={this.handleCheckboxChange}
/>
<FormattedMessage
id='admin.password.number'
defaultMessage='At least one number'
/>
</label>
</div>
<div>
<label className='checkbox-inline'>
<input
type='checkbox'
ref='symbol'
defaultChecked={this.state.passwordSymbol}
name='admin.password.symbol'
onChange={this.handleCheckboxChange}
/>
<FormattedMessage
id='admin.password.symbol'
defaultMessage='At least one symbol (e.g. "~!@#$%^&*()")'
/>
</label>
</div>
<div>
<br/>
<label>
<FormattedMessage
id='admin.password.preview'
defaultMessage='Error message preview:'
/>
</label>
<br/>
{this.sampleErrorMsg}
</div>
</Setting>
</div>
);
}
return (
<SettingsGroup>
{passwordSettings}
<GeneratedSetting
id='passwordResetSalt'
label={
<FormattedMessage
id='admin.email.passwordSaltTitle'
defaultMessage='Password Reset Salt:'
/>
}
helpText={
<FormattedMessage
id='admin.email.passwordSaltDescription'
defaultMessage='32-character salt added to signing of password reset emails. Randomly generated on install. Click "Regenerate" to create new salt.'
/>
}
value={this.state.passwordResetSalt}
onChange={this.handleChange}
disabled={this.state.sendEmailNotifications}
disabledText={
<FormattedMessage
id='admin.security.passwordResetSalt.disabled'
defaultMessage='Password reset salt cannot be changed while sending emails is disabled.'
/>
}
/>
<TextSetting
id='maximumLoginAttempts'
label={
<FormattedMessage
id='admin.service.attemptTitle'
defaultMessage='Maximum Login Attempts:'
/>
}
placeholder={Utils.localizeMessage('admin.service.attemptExample', 'Ex "10"')}
helpText={
<FormattedMessage
id='admin.service.attemptDescription'
defaultMessage='Login attempts allowed before user is locked out and required to reset password via email.'
/>
}
value={this.state.maximumLoginAttempts}
onChange={this.handleChange}
/>
{mfaSetting}
</SettingsGroup>
);
}
}
|