Commit 6ca15cc5 authored by Robert Czechowski's avatar Robert Czechowski

Simplify and unify password and code creation

parent fdc6dd7d
Pipeline #699 passed with stages
in 24 minutes and 52 seconds
......@@ -19,34 +19,40 @@ use rand::{distributions::Alphanumeric, thread_rng, Rng};
use core::MedalError;
use db_objects::SessionUser;
pub fn make_session_token() -> String { thread_rng().sample_iter(&Alphanumeric).take(10).collect() }
pub fn make_ambiguous_code(len: usize) -> String {
thread_rng().sample_iter(&Alphanumeric).take(len).collect()
}
pub fn make_unambiguous_code(len: usize) -> String {
thread_rng().sample_iter(&Alphanumeric)
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(len)
.collect()
}
pub fn make_unambiguous_code_prefix(len: usize, prefix: &str) -> String {
let mut code = prefix.to_owned();
code.push_str(&make_unambiguous_code(len));
code
}
pub fn make_session_token() -> String { make_ambiguous_code(10) }
pub fn make_csrf_token() -> String { thread_rng().sample_iter(&Alphanumeric).take(10).collect() }
pub fn make_csrf_token() -> String { make_ambiguous_code(10) }
pub fn make_salt() -> String { thread_rng().sample_iter(&Alphanumeric).take(10).collect() }
pub fn make_salt() -> String { make_ambiguous_code(10) }
pub fn make_filename_secret() -> String { thread_rng().sample_iter(&Alphanumeric).take(10).collect() }
pub fn make_filename_secret() -> String { make_ambiguous_code(10) }
pub fn make_group_code() -> String {
Some('g').into_iter()
.chain(thread_rng().sample_iter(&Alphanumeric))
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(7)
.collect()
make_unambiguous_code_prefix(6, "g")
}
pub fn make_login_code() -> String {
Some('u').into_iter()
.chain(thread_rng().sample_iter(&Alphanumeric))
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(9)
.collect()
make_unambiguous_code_prefix(8, "u")
}
pub fn hash_password(password: &str, salt: &str) -> Result<String, MedalError> {
......
......@@ -136,25 +136,10 @@ fn add_admin_user<C>(conn: &mut C, resetpw: bool)
}
};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
let password: String = thread_rng().sample_iter(&Alphanumeric)
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(8)
.collect();
let password = helpers::make_unambiguous_code(8);
print!("'{}', ", &password);
let logincode: String = thread_rng().sample_iter(&Alphanumeric)
.filter(|x| {
let x = *x;
!(x == 'l' || x == 'I' || x == '1' || x == 'O' || x == 'o' || x == '0')
})
.take(8)
.collect();
let logincode = format!("a{}", logincode);
let logincode = helpers::make_unambiguous_code_prefix(8, "a");
print!(" logincode:'{}' …", &logincode);
admin.username = Some("admin".into());
......
......@@ -46,7 +46,7 @@
<div class="tile is-parent is-6">
<a href="/contest/?filter=challenge" class="tile is-child notification" style="background-color: #d2222217">
<h3 class="title is-4">Herausforderungen</h3>
<h4 class="subtitle is-5">Mit Zeitbeschränkung</h4>
<h4 class="subtitle is-5">Aufgaben mit und ohne Zeitbeschränkung</h4>
<img src="/static/images/gross.png" style="width:30%; margin: 0px 35% 37px;">
➙ Zu den Herausforderungen …
</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment