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
Magne.Stenseng
inf226-2021-inchat
Commits
b88cd9bc
Commit
b88cd9bc
authored
Nov 14, 2021
by
Magne.Stenseng
Browse files
Replace Account.java
parent
2f765945
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/inf226/inchat/Account.java
View file @
b88cd9bc
package
inf226.inchat
;
import
com.lambdaworks.crypto.SCryptUtil
;
import
inf226.util.immutable.List
;
import
inf226.util.Pair
;
import
inf226.storage.*
;
/**
* The Account class holds all information private to
* a specific user.
...
...
@@ -16,43 +18,40 @@ public final class Account {
*/
public
final
Stored
<
User
>
user
;
public
final
List
<
Pair
<
String
,
Stored
<
Channel
>>>
channels
;
public
final
String
password
;
public
final
Password
password
;
public
Account
(
final
Stored
<
User
>
user
,
final
List
<
Pair
<
String
,
Stored
<
Channel
>>>
channels
,
final
String
password
)
{
final
Password
password
)
{
this
.
user
=
user
;
this
.
channels
=
channels
;
this
.
password
=
password
;
String
password1
=
password
.
getPassword
();
String
sCryptPassword
=
SCryptUtil
.
scrypt
(
password1
,
2
<<
14
,
8
,
1
);
this
.
password
=
new
Password
(
sCryptPassword
);
}
/**
* Create a new Account.
*
* @param user The public User profile for this user.
* @param password
T
he login password for this account.
* @param password
t
he login password for this account.
**/
public
static
Account
create
(
final
Stored
<
User
>
user
,
final
String
password
)
{
public
static
Account
create
(
final
Stored
<
User
>
user
,
final
Password
password
)
{
return
new
Account
(
user
,
List
.
empty
(),
password
);
}
/**
* Join a channel with this account.
*
* @return A new account object with the ca
n
nnel added.
* @return A new account object with the c
h
annel added.
*/
public
Account
joinChannel
(
final
String
alias
,
final
Stored
<
Channel
>
channel
)
{
Pair
<
String
,
Stored
<
Channel
>>
entry
=
new
Pair
<
String
,
Stored
<
Channel
>>(
alias
,
channel
);
return
new
Account
(
user
,
List
.
cons
(
entry
,
channels
),
password
);
}
public
Account
joinChannel
(
final
String
alias
,
final
Stored
<
Channel
>
channel
)
{
Pair
<
String
,
Stored
<
Channel
>>
entry
=
new
Pair
<>(
alias
,
channel
);
return
new
Account
(
user
,
List
.
cons
(
entry
,
channels
),
password
);
}
/**
* Check weather if a string is a correct password for
...
...
@@ -60,8 +59,8 @@ public final class Account {
*
* @return true if password matches.
*/
public
boolean
checkPassword
(
String
password
)
{
return
this
.
password
.
equals
(
p
assword
);
public
boolean
checkPassword
(
Password
password
)
{
return
password
.
checkP
assword
(
);
}
...
...
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