Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating api for Password manager (issue #42) #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,24 @@ Visit the **python** channel and ping `2Y` for assistance.

- **Encrypt and Store Passwords**: Securely save your credentials.
- **Key Management**: Generate and load encryption keys.
- **File-Based Storage**: Organize passwords in a file.
- **File-Based Storage**: Organize passwords in a file.
- **Now handles users via api.

---

## Requirements

- **Python**: Version 3.x or higher.
- **Library**: `cryptography`
- **Library**: `cryptography`,`flask`

---

## How to Use

1. **Start the Program**:
```bash
python3 main.py
python3 main.py
now make a POST request on the /password endpoint which accepts number according to the Menu options and returns a json response
```

2. **Menu Options**:
Expand Down
88 changes: 56 additions & 32 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,77 @@
from flask import Flask,request
from flask_cors import CORS
from manager import PasswordManager


def main():
password = {
app = Flask(__name__)
CORS(app)
app.config['JSON_SORT_KEYS'] = False
password = {
"gmail": "password1",
"facebook": "password2",
"twitter": "password3"
}

pm = PasswordManager()
pm = PasswordManager()

print("""What would you like to do?
1. Create a new key
2. Load an existing key
3. Create a new password file
4. Load an existing password file
5. Add a password
6. Get a password
q. Quit
""")

done = False
while not done:
choice = input("Enter choice: ").strip().lower()

@app.route("/pasword",methods=['GET','POST'])
def password():
if request.method == 'POST':
choice = request.form.get('choice')
if choice == '1':
path = input("Enter key file path: ").strip()
path = request.form.get('path')
pm.create_key(path)
return {
"msg" : "key created successfully",
"path" : path,
"status":"success"
}
elif choice == '2':
path = input("Enter key file path: ").strip()
path = request.form.get('path')
pm.load_key(path)
return {
"msg" : "loaded from path :" + path,
"status" : "success",
}
elif choice == '3':
path = input("Enter password file path: ").strip()
path = request.form.get('path')
pm.create_password_file(path, password)
return {
"status" :"success",
"msg" : "password file created successfully",
"path" : path
}
elif choice == '4':
path = input("Enter password file path: ").strip()
path = request.form.get('path')
pm.load_password_file(path)
return {
"status" : "success",
"msg" : "password file loaded successfully",
"path" : path
}
elif choice == '5':
site = input("Enter site: ").strip()
password = input("Enter password: ").strip()
site = request.form.get('site')
password = request.form.get('password')
pm.add_password(site, password)
return {
"status" : "success",
"msg" : f"password for {site} added successfully"
}
elif choice == '6':
site = input("Enter site: ").strip()
print(f"Password for {site}: {pm.get_password(site)}")
elif choice == 'q':
done = True
print("Goodbye!")
site = request.form.get('site')
password = pm.get_password(site)
return {
"status" : "success",
"msg" : f"password for {site} is {password}"
}



else:
print("Invalid choice. Please try again.")


if __name__ == '__main__':
main()
return {
"status" : "the given choice is invalid",

}
if __name__ == "__main__" :
app.run()