Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
708cd26a
Commit
708cd26a
authored
Feb 12, 2019
by
Daniel Brüning
Browse files
changed location if hash-function to functions.rs
parent
8db05ea3
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/db_conn_sqlite.rs
View file @
708cd26a
...
...
@@ -18,15 +18,6 @@ use self::bcrypt::{DEFAULT_COST, hash, verify, BcryptError};
use
::
functions
;
// todo: remove (usertype in db)
fn
hash_password
(
password
:
&
str
,
salt
:
&
str
)
->
Result
<
String
,
BcryptError
>
{
let
password_and_salt
=
[
password
,
salt
]
.concat
()
.to_string
();
match
hash
(
password_and_salt
,
5
)
{
Ok
(
result
)
=>
Ok
(
result
),
Err
(
e
)
=>
Err
(
e
)
}
}
fn
verify_password
(
password
:
&
str
,
salt
:
&
str
,
password_hash
:
&
str
)
->
bool
{
let
password_and_salt
=
[
password
,
salt
]
.concat
()
.to_string
();
match
verify
(
password_and_salt
,
password_hash
)
{
...
...
src/functions.rs
View file @
708cd26a
extern
crate
bcrypt
;
use
webfw_iron
::{
to_json
,
json_val
};
use
time
;
...
...
@@ -8,6 +10,8 @@ use db_conn::{MedalConnection};
use
db_objects
::{
Submission
,
Group
};
use
self
::
bcrypt
::{
DEFAULT_COST
,
hash
,
verify
,
BcryptError
};
pub
fn
blaa
()
->
(
String
,
json_val
::
Map
<
String
,
json_val
::
Value
>
)
{
let
mut
data
=
json_val
::
Map
::
new
();
...
...
@@ -497,6 +501,13 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: String, user_id
Ok
((
"profile"
.to_string
(),
data
))
}
fn
hash_password
(
password
:
&
str
,
salt
:
&
str
)
->
Result
<
String
,
BcryptError
>
{
let
password_and_salt
=
[
password
,
salt
]
.concat
()
.to_string
();
match
hash
(
password_and_salt
,
5
)
{
Ok
(
result
)
=>
Ok
(
result
),
Err
(
e
)
=>
Err
(
e
)
}
}
pub
fn
edit_profile
<
T
:
MedalConnection
>
(
conn
:
&
T
,
session_token
:
String
,
user_id
:
Option
<
u32
>
,
csrf_token
:
String
,
firstname
:
String
,
lastname
:
String
,
new_password_1
:
String
,
new_password_2
:
String
,
grade
:
u8
)
->
MedalResult
<
()
>
{
let
mut
session
=
conn
.get_session
(
&
session_token
)
.ok_or
(
MedalError
::
AccessDenied
)
?
.ensure_alive
()
.ok_or
(
MedalError
::
AccessDenied
)
?
;
// TODO SessionTimeout
...
...
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