Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
GPA Calculator using React
Next article icon

Build a Password Manager using React

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Password manager using React js provides a secure and user-frie­ndly environment for users to store­ and manage their crede­ntials. It offers convenient fe­atures like adding, editing, and de­leting password entries. The user can show/hide their password by clicking on a particular button.

Preview of final output: Let us have a look at how the final application will look like:

gfg

Prerequisites and Technologies Used:

  • React
  • CSS
  • Class Components in React
  • Conditional Rendering in React

Approach to create the Password Manager:

  • The compone­nt's state is initialized by the constructor with value­s such as website, username­, password, passwords array, and various flags.
  • After the­ component is mounted, the "compone­ntDidMount" function triggers the exe­cution of "showPasswords()". This action effectively re­sets the formand editing mode.
  • The compone­nt's structure is defined in the­ rendering process, which involve­s handling password entries, alerts, and input fie­lds. Additionally, its behavior is adjusted to accommodate the­ addition or editing of entries.

Functionalities to create the Password Manager:

  • maskPassword: Masks the password with asterisks ('*').
  • copyPassword: Asynchronously copies a password to the clipboard.
  • deletePassword: Deletes a password entry and shows a success alert.
  • showPasswords: Resets the component's state, clearing the form and editing mode.
  • savePassword: Adds or updates password entries based on user input.
  • editPassword: Allows editing of existing password entries.
  • renderPasswordList: Generates HTML elements for displaying password entries.

Steps to Create the Password Manager :

Step 1: Create a react application by using this command

npx create-react-app  password-manager-app

Step 2: After creating your project folder, i.e. password-manager-app, use the following command to navigate to it:

cd password-manager-app

Project Structure:

The updated dependencies in package.json file will look like:

"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"react-icons": "^4.11.0"
"web-vitals": "^2.1.4"
}

Example: Write the below code in App.js file and App.css in the src directory

JavaScript
import React, { Component } from 'react'; import './App.css'; import { FaCopy, FaEdit, FaTrash } from 'react-icons/fa';  class App extends Component {   // Constructor to initialize the component's state   constructor(props) {     super(props);      this.state = {       website: '',       username: '',       password: '',       passwords: [],       alertVisible: false,       editing: false,       editIndex: null,       showPassword: false,     };   }    componentDidMount() {     this.showPasswords();   }    // Function to copy a password to the clipboard   copyPassword = async (pass) => {     try {       const textArea = document.createElement('textarea');       textArea.value = pass;       document.body.appendChild(textArea);       textArea.select();       document.execCommand('copy');       document.body.removeChild(textArea);       this.setState({ alertVisible: true });       setTimeout(() => {         this.setState({ alertVisible: false });       }, 2000);     } catch (error) {       console.error('Error copying text:', error);     }   };    // Function to delete a password entry   deletePassword = (website) => {     const updatedPasswords = this.state.passwords.filter(       (e) => e.website !== website     );     this.setState({ passwords: updatedPasswords });     alert(`Successfully deleted ${website}'s password`);   };    // Function to clear the form and reset editing mode   showPasswords = () => {     this.setState({       passwords: [],       website: '',       username: '',       password: '',       editing: false,       editIndex: null,       showPassword: false,     });   };    savePassword = () => {     const { website, username, password, editing, editIndex, passwords } =       this.state;      if (!website || !username || !password) {       alert('Please fill in all fields.');       return;     }      if (editing && editIndex !== null) {       // Replace the old entry with the updated one       const updatedPasswords = [...passwords];       updatedPasswords[editIndex] = {         website,         username,         password,       };       this.setState({         passwords: updatedPasswords,         editing: false,         editIndex: null,         website: '',         username: '',         password: '',       });     } else {       const newPassword = {         website,         username,         password,       };       this.setState((prevState) => ({         // Add the new entry to passwords array         passwords: [...prevState.passwords, newPassword],         website: '',         username: '',         password: '',       }));     }   };    // Function to edit a password entry   editPassword = (index) => {     const { passwords } = this.state;     this.setState({       editing: true,       editIndex: index,       website: passwords[index].website,       username: passwords[index].username,       password: passwords[index].password,     });   };    // Function to toggle password visibility   togglePasswordVisibility = () => {     this.setState((prevState) => ({       showPassword: !prevState.showPassword,     }));   };    renderPasswordList = () => {     const { passwords, showPassword } = this.state;      return passwords.map((item, index) => (       <div className="passwordItem" key={index}>         <div className="listItem">           <div className="listLabel">Website:</div>           <div className="listValue">{item.website}</div>           <div className="listLabel">Username:</div>           <div className="listValue">{item.username}</div>           <div className="listLabel">Password:</div>           <div className="listValue">             <span className="passwordField">               {showPassword ? item.password : item.password.replace(/./g, '*')}             </span>           </div>           <div className="passwordButtons">             <button               className="showPasswordButton"               onClick={this.togglePasswordVisibility}             >               {showPassword ? 'Hide' : 'Show'}             </button>           </div>           <div className="iconContainer">             <div               className="icon"               onClick={() => this.copyPassword(item.password)}             >               <FaCopy size={20} color="#555" />             </div>             <div className="icon" onClick={() => this.editPassword(index)}>               <FaEdit size={20} color="#555" />             </div>             <div               className="icon"               onClick={() => this.deletePassword(item.website)}             >               <FaTrash size={20} color="#555" />             </div>           </div>         </div>       </div>     ));   };    render() {     const { website, username, password, editing } = this.state;      return (       <div className="container">         <div className="content">           <h1 className="heading">Password Manager</h1>           <h2 className="subHeading">             Your Passwords             {this.state.alertVisible && <span id="alert">(Copied!)</span>}           </h2>           {this.state.passwords.length === 0 ? (             <p className="noData">No Data To Show</p>           ) : (             <div className="table">{this.renderPasswordList()}</div>           )}            <h2 className="subHeading">             {editing ? 'Edit Password' : 'Add a Password'}           </h2>           <input             className="input"             placeholder="Website"             value={website}             onChange={(e) => this.setState({ website: e.target.value })}           />           <input             className="input"             placeholder="Username"             value={username}             onChange={(e) => this.setState({ username: e.target.value })}           />           <input             className="input"             placeholder="Password"             type="password"             value={password}             onChange={(e) => this.setState({ password: e.target.value })}           />           <div className="submitButton" onClick={this.savePassword}>             <span className="submitButtonText">               {editing ? 'Update Password' : 'Add Password'}             </span>           </div>         </div>       </div>     );   } }  export default App; 
CSS
body {   background-color: #f0f0f0;   font-family: 'Arial', sans-serif;   display: flex;   justify-content: center;   align-items: center;   height: 100vh;   margin: 0; }  .container {   width: 100%;   text-align: center;   background-color: #fff;   border-radius: 10px;   box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);   padding: 20px; }  .heading {   font-size: 28px;   margin-bottom: 20px;   color: #333; }  .subHeading {   font-size: 20px;   margin-bottom: 15px;   display: flex;   justify-content: space-between;   align-items: center; }  #alert {   color: green;   margin-left: 5px; }  .input {   width: 90%;   padding: 12px;   border: 2px solid #ccc;   border-radius: 5px;   margin: 10px 0;   font-size: 16px; }  .table {   margin: 2rem 0; }  .passwordItem {   background-color: #f9f9f9;   border: 1px solid #ccc;   border-radius: 10px;   padding: 15px;   margin-bottom: 15px; }  .listItem {   display: flex;   justify-content: space-between;   align-items: center;   margin-bottom: 10px;   margin-right: 10px; } .listValue {   margin-right: 15px; } .listLabel {   font-weight: bold;   width: 100px;   padding: 12px;   font-size: 18px; }  .showPasswordIcon {   cursor: pointer;   margin-left: 16px;   color: #007bff;   font-size: 20px;   transition: color 0.3s; }  .showPasswordIcon:hover {   color: #0056b3; }  .copyIcon, editIcon, deleteIcon {   cursor: pointer;   color: #555;   font-size: 20px;   transition: color 0.3s;   margin-left: 10px; }  .copyIcon:hover, editIcon:hover, deleteIcon:hover {   color: #007bff; }  .submitButton {   background: #007bff;   color: #fff;   padding: 12px 24px;   text-align: center;   border: none;   border-radius: 5px;   cursor: pointer;   margin: 12px 0;   font-weight: bold;   font-size: 18px; }  .noData {   text-align: center;   color: #777;   margin-top: 20px;   font-size: 18px; } 

Steps to run the Application:

Step 1: Type the following command in the terminal:

npm start

Step 2: Type the following URL in the browser:

 http://localhost:3000/

Output:gfg


Next Article
GPA Calculator using React
author
saurabhkumarsharma05
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • Web Development Projects
  • ReactJS-Projects
  • Geeks Premier League 2023

Similar Reads

  • Create a Password Manager using React-Native
    This article will demonstrate how to create a Password Manager Application using React-Native. To assist users in securely storing and managing their passwords, we will develop a Password Manager mobile­ application using React Native for this project. The application will provide functionalities su
    6 min read
  • Build a Captcha Generator Using ReactJs
    A CAPTCHA generator is a tool that creates random and visually distorted text, requiring user input to prove they are human. It prevents automated bots from accessing websites or services by testing human comprehension. Our Captcha generator ge­nerates random text-base­d captchas that users must acc
    4 min read
  • Create a Password Validator using ReactJS
    Password must be strong so that hackers can not hack them easily. The following example shows how to check the password strength of the user input password in ReactJS. We will use the validator module to achieve this functionality. We will call the isStrongPassword function and pass the conditions a
    2 min read
  • Build a Random User Generator App Using ReactJS
    In this article, we will create a random user generator application using API and React JS. A Random User Generator App Using React Js is a web application built with the React.js library that generates random user profiles. It typically retrieves and displays details like names, photos, and contact
    4 min read
  • GPA Calculator using React
    GPA Calculator is an application that provides a user interface for calculating and displaying a student's GPA(Grade Point Average). Using functional components and state management, this program enables users to input course information, including course name, credit hours and earned grades and add
    6 min read
  • How to Build Password Generator using Node.js?
    Creating a password generator is a common and practical programming task that helps enhance security by generating random passwords. Using Node.js, you can build a simple and effective password generator with various features, such as customizable length, inclusion of special characters, and more. T
    3 min read
  • Show And Hide Password Using TypeScript
    Managing password visibility in web applications enhances user experience by allowing users to toggle between hidden and visible passwords. TypeScript provides strong type safety and better maintainability for implementing this feature. What We Are Going to CreateWe’ll build an application that allo
    4 min read
  • How to Show and Hide Password in React Native ?
    In this article, we'll see how we can add password show and hide features in React Native applications. In mobile apps, users often need to toggle password visibility for better user experience and accuracy. React Native simplifies this with the `SecureTextEntry` prop in the `TextInput` component, e
    3 min read
  • How to show and hide Password in ReactJS?
    To show and hide passwords in React JS we can simply use the password input with an input to select the show and hide state. The user might need to see what has he used as the password to verify which is an important concept in login and registration forms. We can create this type of password input
    4 min read
  • Build an Online Code Compiler using React.js and Node.js
    In this article, we will learn how to build an online code compiler using React.js as frontend and Express.js as backend. Users will be able to write C, C++, Python, and Java code with proper syntax highlighting as well as compile and execute it online. The main objective of building an online compi
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences