Generate password on frontend instead
This commit is contained in:
3 files changed
+10
-18
No files matched your search
@@ -16,4 +16,3 @@ tauri-build = { version = "2.5.5", features = [] }
|
||||
tauri = { version = "2.10.2", features = [] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
rand = "0.10.0"
|
||||
+1
-14
@@ -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)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![generate_password])
|
||||
.invoke_handler(tauri::generate_handler![])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
+9
-3
@@ -1,5 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import '@fontsource/lexend'
|
||||
import './App.css'
|
||||
|
||||
@@ -10,8 +9,15 @@ function App () {
|
||||
|
||||
const presets = [6, 8, 12, 16, 24, 32, 50, 100, 200, 250]
|
||||
|
||||
const generatePassword = useCallback(async () => {
|
||||
setPassword(await invoke('generate_password', { length }))
|
||||
const generatePassword = useCallback(() => {
|
||||
const chars =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*'
|
||||
setPassword(
|
||||
Array.from(
|
||||
{ length },
|
||||
() => chars[Math.floor(Math.random() * chars.length)]
|
||||
).join('')
|
||||
)
|
||||
}, [length])
|
||||
|
||||
const copyToClipboard = () => {
|
||||
|
||||
Reference in new issue
Block a user