1
1
import React , { ChangeEvent , FormEvent , ReactElement , useEffect , useState } from "react" ;
2
2
import { Container , Row , Col , Form , FormGroup , Button , Alert } from "react-bootstrap" ;
3
3
import { deleteSpaces } from "../../background/methods/strings" ;
4
- import { notMinStrLength } from "../../background/methods/checkInput" ;
4
+ import { biggerMaxStrLength , notMinStrLength } from "../../background/methods/checkInput" ;
5
5
import info_svg from "../../assets/images/icons/material.io/info-24px.svg" ;
6
6
import check_svg from "../../assets/images/icons/material.io/check_circle-24px.svg" ;
7
7
import error_svg from "../../assets/images/icons/material.io/error-24px.svg" ;
8
8
import { registerNewUser } from "../../background/api/registration" ;
9
9
10
10
export default function Registration ( ) : ReactElement {
11
11
const MIN_PASSWORD_LENGTH = 8 ;
12
+ const MAX_PASSWORD_LENGTH = 20 ;
12
13
13
14
const [ username , setUsername ] = useState < string > ( "" ) ;
14
15
const [ password , setPassword ] = useState < string > ( "" ) ;
@@ -68,10 +69,20 @@ export default function Registration(): ReactElement {
68
69
}
69
70
}
70
71
72
+ const makePasswordInputFitRules = ( input :string ) :string | null => {
73
+ input = deleteSpaces ( input ) ;
74
+ if ( biggerMaxStrLength ( input , MAX_PASSWORD_LENGTH ) ) {
75
+ return null
76
+ }
77
+ return input ;
78
+ }
79
+
71
80
const handlePasswordChange = ( event : ChangeEvent < HTMLInputElement > ) => {
72
81
event . preventDefault ( ) ;
73
- let value = event . target . value ;
74
- value = deleteSpaces ( value ) ;
82
+ let value :string | null = makePasswordInputFitRules ( event . target . value ) ;
83
+ if ( ! value ) {
84
+ value = password ;
85
+ }
75
86
setPasswordInformationLength ( ! notMinStrLength ( value , MIN_PASSWORD_LENGTH ) ) ;
76
87
setPasswordInformationLowercase ( value . match ( / [ a - z ] / ) !== null ) ;
77
88
setPasswordInformationUppercase ( value . match ( / [ A - Z ] / ) !== null ) ;
@@ -81,8 +92,10 @@ export default function Registration(): ReactElement {
81
92
82
93
const handlePasswordConfirmationChange = async ( event : ChangeEvent < HTMLInputElement > ) => {
83
94
event . preventDefault ( ) ;
84
- let value = event . target . value ;
85
- value = deleteSpaces ( value ) ;
95
+ let value :string | null = makePasswordInputFitRules ( event . target . value ) ;
96
+ if ( ! value ) {
97
+ value = passwordConfirmation ;
98
+ }
86
99
setPasswordConfirmation ( value ) ;
87
100
}
88
101
0 commit comments