Commit b88cd9bc authored by Magne.Stenseng's avatar Magne.Stenseng
Browse files

Replace Account.java

parent 2f765945
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 The login password for this account.
* @param password the 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 cannnel added.
* @return A new account object with the channel 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(password);
public boolean checkPassword(Password password) {
return password.checkPassword();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment