@app.route("/retrieve_password", methods=["POST"]) def retrieve_password(): user_id = request.json["user_id"] account_name = request.json["account_name"] master_password = request.json["master_password"] user = User.query.get(user_id) if check_password_hash(user.master_password, master_password): password = Password.query.filter_by(user_id=user_id, account_name=account_name).first() decrypted_password = cipher_suite.decrypt(password.password).decode() return jsonify({"password": decrypted_password}) return jsonify({"message": "Invalid master password"}), 401
const handleRetrievePassword = async () => { try { const response = await axios.post("http://localhost:5000/retrieve_password", { user_id: 1, account_name: accountName, master_password: masterPassword, }); console.log(response.data); } catch (error) { console.error(error); } }; scoreland passwords
return ( <div> <h1>ScoreLand Password Manager</h1> <input type="number" value={passwordLength} onChange={(e) => setPasswordLength(e.target.value)} placeholder="Password length" /> <button onClick={handleGeneratePassword}>Generate Password</button> <p>Generated Password: {generatedPassword}</p> <input type="text" value={accountName} onChange={(e) => setAccountName(e.target.value)} placeholder="Account name" /> <button onClick={handleStorePassword}>Store Password</button> <input type="password" value={masterPassword} onChange={(e) => setMasterPassword(e.target.value)} placeholder="Master password" /> <button onClick={handleRetrievePassword}>Retrieve Password</button> </div> ); } { user_id: 1
const handleGeneratePassword = async () => { try { const response = await axios.post("http://localhost:5000/generate_password", { password_length: passwordLength, }); setGeneratedPassword(response.data.password); } catch (error) { console.error(error); } }; } catch (error) { console.error(error)
# Generate a secret key for encryption secret_key = Fernet.generate_key() cipher_suite = Fernet(secret_key)