forked from kobotoolbox/kpi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kobotoolbox#2043 from kobotoolbox/password-strength
Password strength in registration form
- Loading branch information
Showing
8 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import autoBind from 'react-autobind'; | ||
import zxcvbn from 'zxcvbn'; | ||
import bem from '../bem'; | ||
import {t} from '../utils'; | ||
|
||
/* | ||
Properties: | ||
- password <string>: required | ||
*/ | ||
class PasswordStrength extends React.Component { | ||
constructor(props){ | ||
super(props); | ||
autoBind(this); | ||
} | ||
|
||
render() { | ||
const report = zxcvbn(this.props.password); | ||
const barModifier = `score-${report.score}`; | ||
return ( | ||
<bem.PasswordStrength> | ||
<bem.PasswordStrength__title> | ||
{t('Password strength')} | ||
</bem.PasswordStrength__title> | ||
|
||
<bem.PasswordStrength__bar m={barModifier}> | ||
<bem.PasswordStrength__indicator/> | ||
</bem.PasswordStrength__bar> | ||
|
||
{(report.feedback.warning || report.feedback.suggestions.length > 0) && | ||
<bem.PasswordStrength__messages> | ||
{report.feedback.warning && | ||
<bem.PasswordStrength__message m='warning'> | ||
{report.feedback.warning} | ||
</bem.PasswordStrength__message> | ||
} | ||
|
||
{report.feedback.suggestions.length > 0 && | ||
report.feedback.suggestions.map((suggestion, index) => { | ||
return ( | ||
<bem.PasswordStrength__message key={index}> | ||
{suggestion} | ||
</bem.PasswordStrength__message> | ||
) | ||
}) | ||
} | ||
</bem.PasswordStrength__messages> | ||
} | ||
</bem.PasswordStrength> | ||
) | ||
} | ||
} | ||
|
||
export default PasswordStrength; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import PasswordStrength from './components/passwordStrength'; | ||
|
||
const PASS_INPUT_ID = 'id_password1'; | ||
|
||
class RegistrationPasswordApp extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {currentPass: ''} | ||
} | ||
|
||
componentDidMount() { | ||
this.watchInput(PASS_INPUT_ID); | ||
} | ||
|
||
watchInput(inputId) { | ||
const inputEl = document.getElementById(inputId); | ||
if (inputEl) { | ||
inputEl.addEventListener('input', (evt) => { | ||
this.setState({currentPass: evt.currentTarget.value}) | ||
}); | ||
} else { | ||
throw new Error(`Input "${inputId}" not found!`); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<PasswordStrength password={this.state.currentPass} /> | ||
); | ||
} | ||
}; | ||
|
||
export default RegistrationPasswordApp; |
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,63 @@ | ||
.password-strength { | ||
width: 100%; | ||
font-size: 0.9em; | ||
} | ||
|
||
.password-strength__title, | ||
.password-strength__bar { | ||
margin-bottom: 10px; | ||
} | ||
|
||
.password-strength__bar { | ||
width: 100%; | ||
height: 5px; | ||
position: relative; | ||
box-shadow: inset 0 0 0 1px $cool-silver; | ||
|
||
.password-strength__indicator { | ||
background: blue; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
transition: 0.25s; | ||
} | ||
|
||
&.password-strength__bar--score-0 { | ||
.password-strength__indicator { | ||
width: 1%; | ||
background-color: $cool-red; | ||
} | ||
} | ||
|
||
&.password-strength__bar--score-1 { | ||
.password-strength__indicator { | ||
width: 25%; | ||
background-color: $cool-red; | ||
} | ||
} | ||
&.password-strength__bar--score-2 { | ||
.password-strength__indicator { | ||
width: 50%; | ||
background-color: $cool-orange; | ||
} | ||
} | ||
&.password-strength__bar--score-3 { | ||
.password-strength__indicator { | ||
width: 75%; | ||
background-color: $warm-green; | ||
} | ||
} | ||
&.password-strength__bar--score-4 { | ||
.password-strength__indicator { | ||
width: 100%; | ||
background-color: $cool-blue; | ||
} | ||
} | ||
} | ||
|
||
.password-strength__message { | ||
&.password-strength__message--warning { | ||
color: $cool-red; | ||
} | ||
} |
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