Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Backend improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Aug 12, 2022
1 parent 570abdf commit d30eb6b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
18 changes: 16 additions & 2 deletions core/src/encrypt_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use argon2::{
Argon2,
};

static mut storedPassword: String = String::new();

#[tauri::command]
pub fn encrypt_password(password: String) -> String {
let salt = SaltString::generate(&mut OsRng);
Expand All @@ -27,13 +29,25 @@ pub fn encrypt_password(password: String) -> String {

#[tauri::command]
pub fn verify_password(password: String, hash: String) -> bool {
let password = password.as_bytes();

let parsed_hash = PasswordHash::new(&hash).unwrap();

let result = Argon2::default()
.verify_password(password, &parsed_hash)
.verify_password(password.as_bytes(), &parsed_hash)
.is_ok();

if result {
unsafe {
storedPassword = password;
}
}

result.into()
}

#[tauri::command]
pub fn request_password() -> String {
unsafe {
storedPassword.as_str().into()
}
}
16 changes: 11 additions & 5 deletions core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn handle_tray_event(app: &AppHandle, event: SystemTrayEvent) {
if id.as_str() == "exit" {
std::process::exit(0);
}

if id.as_str() == "toggle" {
let window = app.get_window("main").unwrap();
let menu_item = app.tray_handle().get_item("toggle");
Expand All @@ -31,10 +32,6 @@ fn handle_tray_event(app: &AppHandle, event: SystemTrayEvent) {
window.hide().unwrap();
menu_item.set_title("Show Authme").unwrap();
} else {
#[cfg(target_os = "windows")]
apply_mica(&window)
.expect("Unsupported platform! 'apply_blur' is only supported on Windows");

window.show().unwrap();
menu_item.set_title("Hide Authme").unwrap();
}
Expand All @@ -50,7 +47,8 @@ fn main() {
// auto_launch::auto_launch,
system_info::system_info,
encrypt_password::encrypt_password,
encrypt_password::verify_password
encrypt_password::verify_password,
encrypt_password::request_password
])
.system_tray(make_tray())
.on_system_tray_event(handle_tray_event)
Expand All @@ -73,6 +71,14 @@ fn main() {

Ok(())
})
.on_window_event(|event| match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
api.prevent_close();

event.window().hide().unwrap();
}
_ => {}
})
.run(context)
.expect("error while running tauri application");
}

0 comments on commit d30eb6b

Please sign in to comment.