Skip to content

Commit

Permalink
Merge pull request #29 from aryadevesh/password-generator-feature
Browse files Browse the repository at this point in the history
Added the password generator feature
  • Loading branch information
jinx-vi-0 authored Oct 5, 2024
2 parents d6e8060 + 608096e commit b03a3ea
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/Manager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ const Manager = () => {
? "icons/eye.png"
: "icons/eyecross.png";
};

const generatePassword = () => {
const lowerCase = 'abcdefghijklmnopqrstuvwxyz';
const upperCase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numbers = '0123456789';
const symbols = '!@#$%^&*()_+[]{}|;:,.<>?';

const allChars = lowerCase + upperCase + numbers + symbols;
let generatedPassword = '';

for (let i = 0; i < 12; i++) {
const randomChar = allChars[Math.floor(Math.random() * allChars.length)];
generatedPassword += randomChar;
}
// Set the generated password into the form's password field
setForm((prevForm) => ({ ...prevForm, password: generatedPassword }));
};


const validatePassword = (password) => {
const errors = Object.keys(passwordRules)
Expand Down Expand Up @@ -258,6 +276,15 @@ const Manager = () => {
)}
</div>
</div>

{/* Add a button to generate a password */}
<button
onClick={generatePassword}
className="bg-green-600 hover:bg-green-600 text-white rounded-full px-4 py-2"
>
Generate Password
</button>

<button
onClick={savePassword}
className="flex justify-center items-center gap-2 bg-green-500 hover:bg-green-600 rounded-full px-8 py-2 w-fit border border-green-900"
Expand Down

0 comments on commit b03a3ea

Please sign in to comment.