mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can crypt user password
This commit is contained in:
parent
fc24b8f747
commit
6f6cd550ea
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -515,6 +515,7 @@ dependencies = [
|
|||||||
"mysql",
|
"mysql",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"serde",
|
"serde",
|
||||||
|
"sha1",
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -16,3 +16,4 @@ futures = "0.3.5"
|
|||||||
encoding_rs = "0.8.23"
|
encoding_rs = "0.8.23"
|
||||||
percent-encoding = "2.1.0"
|
percent-encoding = "2.1.0"
|
||||||
mailchecker = "3.3.6"
|
mailchecker = "3.3.6"
|
||||||
|
sha1 = "0.6.0"
|
@ -2,5 +2,6 @@ pub mod data;
|
|||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
pub mod controllers;
|
pub mod controllers;
|
||||||
pub mod api_data;
|
pub mod api_data;
|
||||||
|
pub mod utils;
|
||||||
|
|
||||||
pub mod database_structure;
|
pub mod database_structure;
|
47
src/utils/crypt_utils.rs
Normal file
47
src/utils/crypt_utils.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
//! # Cryptographic utilities
|
||||||
|
//!
|
||||||
|
//! Author: Pierre Hubert
|
||||||
|
|
||||||
|
extern crate sha1;
|
||||||
|
|
||||||
|
use crate::data::error::{ResultBoxError, ExecError};
|
||||||
|
|
||||||
|
/// Generate a new sha1 string
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use comunic_server::utils::crypt_utils::sha1_str;
|
||||||
|
///
|
||||||
|
/// let res = sha1_str("secret");
|
||||||
|
/// assert_eq!(res, "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4");
|
||||||
|
/// ```
|
||||||
|
pub fn sha1_str(input: &str) -> String {
|
||||||
|
sha1::Sha1::from(input).digest().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One-way user password crypt
|
||||||
|
///
|
||||||
|
/// This method will have to be replaced by a stronger algorithm once this implementation is
|
||||||
|
/// completely built.
|
||||||
|
///
|
||||||
|
/// It currently depends on PHP
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use comunic_server::utils::crypt_utils::crypt_pass;
|
||||||
|
///
|
||||||
|
/// let res = crypt_pass("secret").unwrap();
|
||||||
|
/// assert_eq!(res, "e5GUe5kdeUMGs");
|
||||||
|
/// ```
|
||||||
|
pub fn crypt_pass(pass: &str) -> ResultBoxError<String> {
|
||||||
|
let hash = sha1_str(pass);
|
||||||
|
|
||||||
|
let result = std::process::Command::new("/usr/bin/php")
|
||||||
|
.arg("-r")
|
||||||
|
.arg(format!("echo crypt('{}', '{}');", hash, hash))
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
if !result.status.success() {
|
||||||
|
return Err(ExecError::boxed_new("Failed to crypt password!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(String::from_utf8(result.stdout)?)
|
||||||
|
}
|
5
src/utils/mod.rs
Normal file
5
src/utils/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//! # Utilities
|
||||||
|
//!
|
||||||
|
//! This module contains utilities that can be used anywhere in the code
|
||||||
|
|
||||||
|
pub mod crypt_utils;
|
Loading…
Reference in New Issue
Block a user