-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added password complexity indicator to register * added password complexity indicator to change password
- Loading branch information
Showing
9 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Components/Indicators/PasswordComplexityIndicator/PasswordComplexityIndicator.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useEffect } from "react"; | ||
|
||
import { bytesLength } from "../../../utils/index.js"; | ||
|
||
import "./PasswordComplexityIndicator.scss"; | ||
|
||
const PasswordComplexityIndicator = ({ | ||
password, | ||
complexity, | ||
setComplexity, | ||
}) => { | ||
useEffect(() => { | ||
const passwordLength = bytesLength(password); | ||
|
||
const length = passwordLength >= 8 && passwordLength <= 72; | ||
const hasUpperCase = /[A-Z]/.test(password); | ||
const hasLowerCase = /[a-z]/.test(password); | ||
const hasNumbers = /\d/.test(password); | ||
const hasNonAlphas = /\W/.test(password); | ||
|
||
if (length) { | ||
setComplexity( | ||
length + hasUpperCase + hasLowerCase + hasNumbers + hasNonAlphas | ||
); | ||
} else if (passwordLength !== 0) { | ||
setComplexity(1); | ||
} else { | ||
setComplexity(0); | ||
} | ||
}, [password, setComplexity]); | ||
|
||
return ( | ||
<div className="password-complexity-indicator"> | ||
<div | ||
style={{ width: `${(100 / 5) * complexity}%` }} | ||
className={`bar complexity-${complexity}`} | ||
></div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PasswordComplexityIndicator; |
31 changes: 31 additions & 0 deletions
31
src/Components/Indicators/PasswordComplexityIndicator/PasswordComplexityIndicator.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@import "../../../colors"; | ||
|
||
.password-complexity-indicator { | ||
margin-top: 12px; | ||
width: 100%; | ||
height: 6px; | ||
border-radius: 5px; | ||
background-color: #eee; | ||
|
||
.bar { | ||
border-radius: 3px; | ||
transition: all 0.25s ease-in; | ||
width: 0%; | ||
height: 6px; | ||
|
||
&.complexity-0, | ||
&.complexity-1, | ||
&.complexity-2 { | ||
background-color: $color-red; | ||
} | ||
|
||
&.complexity-3 { | ||
background-color: $color-yellow; | ||
} | ||
|
||
&.complexity-4, | ||
&.complexity-5 { | ||
background-color: $color-green; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
@import "../../colors"; | ||
|
||
.login-form { | ||
max-width: 450px; | ||
max-height: 550px; | ||
|
||
margin: auto; | ||
border-radius: 10px; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters