PasswordConditionsHelper.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. export type PasswordConditionsHelperProps = {
  2. password: string
  3. }
  4. const PasswordConditionsHelper = ({ password }: PasswordConditionsHelperProps) => {
  5. const isEightCharactersLong = password.length >= 8
  6. const hasUppercase = /[A-Z]/.test(password)
  7. const hasLowercase = /[a-z]/.test(password)
  8. const hasNumber = /[0-9]/.test(password)
  9. const hasSpecialCharacter = /[!@#$%^&*()_+\-=\[\]{};`':"\\|,.<>\/?]/.test(password)
  10. return (
  11. <div className="text-sm">
  12. <PasswordCondition title="Uppercase letter" isMet={hasUppercase} />
  13. <PasswordCondition title="Lowercase letter" isMet={hasLowercase} />
  14. <PasswordCondition title="Number" isMet={hasNumber} />
  15. <PasswordCondition title="Special character (e.g. !?<>@#$%)" isMet={hasSpecialCharacter} />
  16. <PasswordCondition title="8 characters or more" isMet={isEightCharactersLong} />
  17. {password.length > 72 && <PasswordCondition title="72 characters or less" isMet={false} />}
  18. </div>
  19. )
  20. }
  21. export default PasswordConditionsHelper
  22. type PasswordConditionProps = {
  23. title: string
  24. isMet: boolean
  25. }
  26. const PasswordCondition = ({ title, isMet }: PasswordConditionProps) => {
  27. return (
  28. <div
  29. className={
  30. 'flex items-center gap-1 space-x-1.5 transition duration-200 ' +
  31. (isMet ? 'text-foreground-light' : 'text-foreground-lighter')
  32. }
  33. >
  34. {isMet ? (
  35. <svg
  36. xmlns="http://www.w3.org/2000/svg"
  37. viewBox="0 0 24 24"
  38. fill="currentColor"
  39. className="w-4 h-4"
  40. >
  41. <path
  42. fillRule="evenodd"
  43. d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm13.36-1.814a.75.75 0 10-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.14-.094l3.75-5.25z"
  44. clipRule="evenodd"
  45. />
  46. </svg>
  47. ) : (
  48. <svg
  49. xmlns="http://www.w3.org/2000/svg"
  50. fill="none"
  51. stroke="currentColor"
  52. strokeWidth={1.5}
  53. viewBox="0 0 24 24"
  54. className="w-4 h-4"
  55. >
  56. <path
  57. strokeLinecap="round"
  58. strokeLinejoin="round"
  59. d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z"
  60. />
  61. </svg>
  62. )}
  63. <p className="text-sm">{title}</p>
  64. </div>
  65. )
  66. }