Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
medal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
43
Issues
43
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bwinf
medal
Commits
6ca15cc5
Commit
6ca15cc5
authored
Jul 07, 2020
by
Robert Czechowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify and unify password and code creation
parent
fdc6dd7d
Pipeline
#699
passed with stages
in 24 minutes and 52 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
38 deletions
+29
-38
src/helpers.rs
src/helpers.rs
+26
-20
src/main.rs
src/main.rs
+2
-17
templates/jwinf/index.hbs
templates/jwinf/index.hbs
+1
-1
No files found.
src/helpers.rs
View file @
6ca15cc5
...
...
@@ -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
>
{
...
...
src/main.rs
View file @
6ca15cc5
...
...
@@ -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
());
...
...
templates/jwinf/index.hbs
View file @
6ca15cc5
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment