-
Notifications
You must be signed in to change notification settings - Fork 558
Expand file tree
/
Copy pathmfa_code.js
More file actions
32 lines (25 loc) · 794 Bytes
/
mfa_code.js
File metadata and controls
32 lines (25 loc) · 794 Bytes
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
import { setField } from './index';
import { validateEmail } from './email';
import { databaseConnection } from '../connection/database';
const DEFAULT_VALIDATION = { mfa_code: { length: 6 } };
const regExp = /^[0-9]+$/;
function validateMFACode(str, settings = DEFAULT_VALIDATION.mfa_code) {
const value = str.trim();
// check min value matched
if (value.length < settings.length) {
return false;
}
// check max value matched
if (value.length > settings.length) {
return false;
}
// check allowed characters matched
const result = regExp.exec(value);
return result && result[0];
}
export function setMFACode(m, str) {
return setField(m, 'mfa_code', str, validateMFACode);
}
export function getMFACodeValidation(m) {
return DEFAULT_VALIDATION.mfa_code;
}