Generate password on frontend instead

This commit is contained in:
Lncvrt committed 2026-02-18 00:33:33 -07:00
1 parent dff4b45adf
commit 3a1815aec3
3 files changed
+10 -18

No files matched your search

-1
View File
@@ -16,4 +16,3 @@ tauri-build = { version = "2.5.5", features = [] }
tauri = { version = "2.10.2", features = [] } tauri = { version = "2.10.2", features = [] }
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149" serde_json = "1.0.149"
rand = "0.10.0"
+1 -14
View File
@@ -1,20 +1,7 @@
use rand::RngExt;
#[tauri::command]
fn generate_password(length: u8) -> String {
let chars: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*"
.chars()
.collect();
let mut rng = rand::rng();
(0..length)
.map(|_| chars[rng.random_range(0..chars.len())])
.collect()
}
#[cfg_attr(mobile, tauri::mobile_entry_point)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
tauri::Builder::default() tauri::Builder::default()
.invoke_handler(tauri::generate_handler![generate_password]) .invoke_handler(tauri::generate_handler![])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }
+9 -3
View File
@@ -1,5 +1,4 @@
import { useState, useEffect, useCallback } from 'react' import { useState, useEffect, useCallback } from 'react'
import { invoke } from '@tauri-apps/api/core'
import '@fontsource/lexend' import '@fontsource/lexend'
import './App.css' import './App.css'
@@ -10,8 +9,15 @@ function App () {
const presets = [6, 8, 12, 16, 24, 32, 50, 100, 200, 250] const presets = [6, 8, 12, 16, 24, 32, 50, 100, 200, 250]
const generatePassword = useCallback(async () => { const generatePassword = useCallback(() => {
setPassword(await invoke('generate_password', { length })) const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*'
setPassword(
Array.from(
{ length },
() => chars[Math.floor(Math.random() * chars.length)]
).join('')
)
}, [length]) }, [length])
const copyToClipboard = () => { const copyToClipboard = () => {