Created
September 28, 2024 14:24
-
-
Save gtchakama/36eb9eac280b5fc2e3ac30fb058744ee to your computer and use it in GitHub Desktop.
Password Verification Component
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
"use client"; | |
import React, { useState } from 'react'; | |
import { EyeIcon, EyeOffIcon } from 'lucide-react'; | |
const PasswordVerification = () => { | |
const [password, setPassword] = useState(''); | |
const [confirmPassword, setConfirmPassword] = useState(''); | |
const [showPassword, setShowPassword] = useState(false); | |
const handlePasswordChange = (e) => { | |
setPassword(e.target.value); | |
}; | |
const handleConfirmPasswordChange = (e) => { | |
setConfirmPassword(e.target.value); | |
}; | |
const toggleShowPassword = () => { | |
setShowPassword(!showPassword); | |
}; | |
return ( | |
<div className="max-w-md mx-auto mt-10 p-6 bg-white rounded-lg shadow-md"> | |
<h2 className="text-2xl font-bold mb-4">Password Verification</h2> | |
<div className="mb-4"> | |
<label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-1"> | |
Password | |
</label> | |
<div className="relative"> | |
<input | |
type={showPassword ? 'text' : 'password'} | |
id="password" | |
value={password} | |
onChange={handlePasswordChange} | |
className="w-full px-3 py-2 border rounded-md" | |
/> | |
<button | |
type="button" | |
onClick={toggleShowPassword} | |
className="absolute inset-y-0 right-0 pr-3 flex items-center" | |
> | |
{showPassword ? ( | |
<EyeOffIcon className="h-5 w-5 text-gray-400" /> | |
) : ( | |
<EyeIcon className="h-5 w-5 text-gray-400" /> | |
)} | |
</button> | |
</div> | |
</div> | |
<div className="mb-4"> | |
<label htmlFor="confirmPassword" className="block text-sm font-medium text-gray-700 mb-1"> | |
Confirm Password | |
</label> | |
<input | |
type="password" | |
id="confirmPassword" | |
value={confirmPassword} | |
onChange={handleConfirmPasswordChange} | |
className="w-full px-3 py-2 border rounded-md" | |
/> | |
</div> | |
<div className="mt-4"> | |
<h3 className="text-lg font-semibold mb-2">Password Comparison</h3> | |
<div className="flex flex-wrap"> | |
{password.split('').map((char, index) => ( | |
<span | |
key={index} | |
className={`inline-block w-8 h-8 mr-1 mb-1 text-center leading-8 rounded ${index < confirmPassword.length | |
? char === confirmPassword[index] | |
? 'bg-green-200' | |
: 'bg-red-200' | |
: 'bg-gray-200' | |
}`} | |
> | |
{'•'} | |
</span> | |
))} | |
</div> | |
</div> | |
</div> | |
); | |
}; | |
export default PasswordVerification; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Password Verification Component
This React component provides a user-friendly interface for password input and verification. It includes real-time visual feedback to help users ensure their password confirmation matches their initial input.
Features
Installation
Make sure you have React and Tailwind CSS set up in your project.
Install the required dependencies:
or if you're using yarn:
Copy the
PasswordVerification.js
component into your project.Usage
Import and use the component in your React application:
Customization
You can customize the component's appearance by modifying the Tailwind CSS classes in the component file. The component uses Tailwind's utility classes for styling, making it easy to adjust colors, spacing, and other visual properties.
Dependencies
Created by George Chakama