Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vetle.Hjelmtvedt
inf226-2021-inchat
Commits
822d7134
Commit
822d7134
authored
Nov 10, 2021
by
vehjelmtvedt
Browse files
scrypt password in create method instead and implement login
parent
556fb407
Changes
4
Hide whitespace changes
Inline
Side-by-side
production.db
View file @
822d7134
No preview for this file type
src/main/java/inf226/inchat/Account.java
View file @
822d7134
...
...
@@ -17,20 +17,16 @@ public final class Account {
*/
public
final
Stored
<
User
>
user
;
public
final
List
<
Pair
<
String
,
Stored
<
Channel
>>>
channels
;
public
final
String
p
assword
;
public
final
String
hashedP
assword
;
// Scrypt parameters
private
final
int
CPUCost
=
16384
;
private
final
int
memCost
=
8
;
private
final
int
parallelization
=
1
;
public
Account
(
final
Stored
<
User
>
user
,
final
List
<
Pair
<
String
,
Stored
<
Channel
>>>
channels
,
final
String
p
assword
)
{
final
String
hashedP
assword
)
{
this
.
user
=
user
;
this
.
channels
=
channels
;
// Hash password with Scrypt
this
.
p
assword
=
SCryptUtil
.
scrypt
(
password
,
CPUCost
,
memCost
,
parallelization
)
;
this
.
hashedP
assword
=
hashedPassword
;
}
/**
...
...
@@ -41,7 +37,7 @@ public final class Account {
**/
public
static
Account
create
(
final
Stored
<
User
>
user
,
final
String
password
)
{
return
new
Account
(
user
,
List
.
empty
(),
password
);
return
new
Account
(
user
,
List
.
empty
(),
SCryptUtil
.
scrypt
(
password
,
16384
,
8
,
1
)
);
}
/**
...
...
@@ -68,7 +64,8 @@ public final class Account {
* @return true if password matches.
*/
public
boolean
checkPassword
(
String
password
)
{
return
this
.
password
.
equals
(
password
);
// Use scrypt to check if hashes match
return
SCryptUtil
.
check
(
password
,
this
.
password
);
}
...
...
src/main/java/inf226/inchat/AccountStorage.java
View file @
822d7134
...
...
@@ -49,7 +49,7 @@ public final class AccountStorage
statement
.
setObject
(
1
,
stored
.
identity
);
statement
.
setObject
(
2
,
stored
.
version
);
statement
.
setObject
(
3
,
account
.
user
.
identity
);
statement
.
setString
(
4
,
account
.
p
assword
);
statement
.
setString
(
4
,
account
.
hashedP
assword
);
statement
.
executeUpdate
();
...
...
src/main/java/inf226/inchat/InChat.java
View file @
822d7134
...
...
@@ -90,7 +90,8 @@ public class InChat {
final
Stored
<
Session
>
session
=
sessionStore
.
save
(
new
Session
(
account
,
Instant
.
now
().
plusSeconds
(
60
*
60
*
24
)));
// Check that password is not incorrect and not too long.
if
(!(!
account
.
value
.
password
.
equals
(
password
)
&&
!(
password
.
length
()
>
1000
)))
{
// Use check method in Account
if
(
account
.
value
.
checkPassword
(
password
))
{
result
.
accept
(
session
);
}
});
...
...
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