PasswordStrength.tsx 801 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. export interface Props {
  3. password: string;
  4. }
  5. export class PasswordStrength extends React.Component<Props, any> {
  6. constructor(props) {
  7. super(props);
  8. }
  9. render() {
  10. const { password } = this.props;
  11. let strengthText = 'strength: strong like a bull.';
  12. let strengthClass = 'password-strength-good';
  13. if (!password) {
  14. return null;
  15. }
  16. if (password.length <= 8) {
  17. strengthText = 'strength: you can do better.';
  18. strengthClass = 'password-strength-ok';
  19. }
  20. if (password.length < 4) {
  21. strengthText = 'strength: weak sauce.';
  22. strengthClass = 'password-strength-bad';
  23. }
  24. return (
  25. <div className={`password-strength small ${strengthClass}`}>
  26. <em>{strengthText}</em>
  27. </div>
  28. );
  29. }
  30. }