11import { Component } from "preact" ;
22import { Button , Form } from "react-bootstrap"
33import { showAlert } from "./Alert" ;
4- import { PASSWORD_PATTERN , fetchClient , generate_hash , generate_random_bytes , get_salt } from "../utils" ;
4+ import { fetchClient , generate_hash , generate_random_bytes , get_salt } from "../utils" ;
55import sodium from "libsodium-wrappers" ;
66import { Trans , useTranslation } from "react-i18next" ;
77import i18n from "../i18n" ;
@@ -24,7 +24,6 @@ interface RegisterSchema {
2424interface RegisterState {
2525 accepted : boolean ,
2626 password : string ,
27- passwordValid : boolean ,
2827 confirmPassword : string ,
2928 confirmPasswordValid : boolean ,
3029 name : string ,
@@ -47,7 +46,6 @@ export class Register extends Component<{}, RegisterState> {
4746 this . state = {
4847 accepted : false ,
4948 password : "" ,
50- passwordValid : true ,
5149 confirmPassword : "" ,
5250 confirmPasswordValid : true ,
5351 name : "" ,
@@ -73,13 +71,6 @@ export class Register extends Component<{}, RegisterState> {
7371 let res = true ;
7472
7573 const state = this . state as RegisterState ;
76- const passwordPatternValid = PASSWORD_PATTERN . test ( this . state . password ) ;
77- if ( ! passwordPatternValid ) {
78- state . passwordValid = false ;
79- res = false ;
80- } else {
81- state . passwordValid = true ;
82- }
8374
8475 const passwordsMatch = this . state . password === this . state . confirmPassword ;
8576 if ( ! passwordsMatch ) {
@@ -237,20 +228,24 @@ export class Register extends Component<{}, RegisterState> {
237228 </ Form . Group >
238229 < Form . Group className = "mb-3" controlId = "registerPassword" >
239230 < Form . Label > { t ( "password" ) } </ Form . Label >
240- < PasswordComponent isInvalid = { ! this . state . passwordValid } onChange = { ( e ) => {
241- this . setState ( { password : e } , async ( ) => {
242- if ( ! this . state . confirmPasswordValid || ! this . state . passwordValid ) {
243- await this . checkPassword ( ) ;
244- }
245- } ) ;
246- } }
247- invalidMessage = { t ( "password_error_message" ) } />
231+ < PasswordComponent
232+ value = { this . state . password }
233+ showStrength = { true }
234+ onChange = { ( e ) => {
235+ this . setState ( { password : e } , async ( ) => {
236+ if ( ! this . state . confirmPasswordValid ) {
237+ await this . checkPassword ( ) ;
238+ }
239+ } ) ;
240+ } }
241+ isInvalid = { this . state . password . length < 8 }
242+ invalidMessage = { t ( "password_error_message" ) } />
248243 </ Form . Group >
249244 < Form . Group className = "mb-3" controlId = "registerConfirmPassword" >
250245 < Form . Label > { t ( "confirm_password" ) } </ Form . Label >
251- < PasswordComponent isInvalid = { ! this . state . confirmPasswordValid } onChange = { ( e ) => {
246+ < PasswordComponent value = { this . state . confirmPassword } isInvalid = { ! this . state . confirmPasswordValid } onChange = { ( e ) => {
252247 this . setState ( { confirmPassword : e } , ( ) => {
253- if ( ! this . state . confirmPasswordValid || ! this . state . passwordValid ) {
248+ if ( ! this . state . confirmPasswordValid ) {
254249 this . checkPassword ( ) ;
255250 }
256251 } ) ;
0 commit comments