Files
supabase/apps/studio/components/ui/PasswordStrengthBar.tsx
Alaister YoungandCharis a3e7cb7285 chore: move password check to frontend (#39927)
* chore: move password check to frontend

* remove barrel file export and fix test import

* move import inside function

* Update apps/studio/lib/password-strength.ts

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>

* fix test

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
2025-10-28 23:24:35 +08:00

55 lines
1.6 KiB
TypeScript

import { PASSWORD_STRENGTH_COLOR, PASSWORD_STRENGTH_PERCENTAGE } from 'lib/constants'
interface Props {
passwordStrengthScore: number
passwordStrengthMessage: string
password: string
generateStrongPassword: () => void
}
const PasswordStrengthBar = ({
passwordStrengthScore = 0,
passwordStrengthMessage = '',
password = '',
generateStrongPassword,
}: Props) => {
return (
<>
{password && (
<div
aria-valuemax={100}
aria-valuemin={0}
aria-valuenow={(PASSWORD_STRENGTH_PERCENTAGE as any)[passwordStrengthScore]}
aria-valuetext={(PASSWORD_STRENGTH_PERCENTAGE as any)[passwordStrengthScore]}
role="progressbar"
className="mb-2 overflow-hidden transition-all border rounded bg-200 w-full"
>
<div
style={{
width: (PASSWORD_STRENGTH_PERCENTAGE as any)[passwordStrengthScore],
}}
className={`relative h-1 w-full ${
(PASSWORD_STRENGTH_COLOR as any)[passwordStrengthScore]
} transition-all duration-500 ease-out shadow-inner`}
/>
</div>
)}
<p>
{(passwordStrengthMessage
? passwordStrengthMessage
: 'This is the password to your Postgres database, so it must be strong and hard to guess.') +
' '}
<span
className="text-inherit underline hover:text-foreground transition-colors cursor-pointer"
onClick={generateStrongPassword}
>
Generate a password
</span>
.
</p>
</>
)
}
export default PasswordStrengthBar