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
980aa59d
Commit
980aa59d
authored
Nov 10, 2021
by
Vetle.Hjelmtvedt
Browse files
Merge branch 'task0A' into 'master'
Task0 a See merge request
!3
parents
5ed54ee1
4d5c767f
Changes
4
Hide whitespace changes
Inline
Side-by-side
production.db
View file @
980aa59d
No preview for this file type
src/main/java/inf226/inchat/Account.java
View file @
980aa59d
package
inf226.inchat
;
import
com.lambdaworks.crypto.SCryptUtil
;
import
inf226.util.immutable.List
;
import
inf226.util.Pair
;
...
...
@@ -16,14 +17,16 @@ public final class Account {
*/
public
final
Stored
<
User
>
user
;
public
final
List
<
Pair
<
String
,
Stored
<
Channel
>>>
channels
;
public
final
String
password
;
public
final
String
hashedPassword
;
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
;
this
.
password
=
password
;
// Hash password with Scrypt
this
.
hashedPassword
=
hashedPassword
;
}
/**
...
...
@@ -34,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
)
);
}
/**
...
...
@@ -50,7 +53,7 @@ public final class Account {
(
user
,
List
.
cons
(
entry
,
channels
),
p
assword
);
hashedP
assword
);
}
...
...
@@ -61,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
.
hashedPassword
);
}
...
...
src/main/java/inf226/inchat/AccountStorage.java
View file @
980aa59d
...
...
@@ -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 @
980aa59d
...
...
@@ -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