Skip to content

Commit

Permalink
Merge pull request #87 from aspiringdevslog/v1.2-toBeMerged
Browse files Browse the repository at this point in the history
this commit resolves #37, #41, #62 and #63: v1.2 Security System; encryption and decryption of data files
  • Loading branch information
aspiringdevslog authored Oct 15, 2018
2 parents 5ec6d9b + 4e03260 commit e9bfd58
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 21 deletions.
12 changes: 6 additions & 6 deletions docs/AboutUs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ We are a team based in the http://www.comp.nus.edu.sg[School of Computing, Natio

== Project Team

=== Happytreat
image::happytreat.png[width="150", align="left"]
=== SIM MING HUI MELODIES
image::Happytreat.png[width="150", align="left"]
{empty}[http://github.com/happytreat[github]] [<<johndoe#, portfolio>>]

Role: Developer +
Responsibilities:

'''

=== ZhiWei94
=== TAN ZHI WEI
image::zhiwei94.png[width="150", align="left"]
{empty}[http://github.com/ZhiWei94[github]] [<<johndoe#, portfolio>>]

Expand All @@ -28,7 +28,7 @@ Responsibilities:

'''

=== Chia Wen Kai
=== CHIA WEN KAI
image::souless94.png[width="150", align="left"]
{empty}[http://github.com/souless94[github]] [<<johndoe#, portfolio>>]

Expand All @@ -37,14 +37,14 @@ Responsibilities:

'''

=== aspiringdevslog
=== TANG WEE JIE LESLIE
image::aspiringdevslog.png[width="150", align="left"]
{empty}[http://github.com/aspiringdevslog[github]] [<<johndoe#, portfolio>>]

Role: Developer +
Responsibilities:

=== nigelngyy
=== NG YUAN YUN NIGEL
image::nigelngyy.png[width="150", align="left"]
{empty}[http://github.com/nigelngyy[github]] [<<johndoe#, portfolio>>]

Expand Down
2 changes: 1 addition & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ Login into the system. +
Format: `login u/USERNAME pw/PASSWORD`
Examples:

* `login u/sampleUser pw/dontUseWeakPassword`
* `login u/username pw/dontUseWeakPassword`

=== Changing password: `update_pw `

Expand Down
Binary file added docs/images/Happytreat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions src/main/java/seedu/address/logic/commands/CreateCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PASSWORD;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_USERNAME;
Expand All @@ -10,12 +11,14 @@
import seedu.address.model.person.Accounts;
import seedu.address.storage.UserAccountStorage;

//@@author aspiringdevslog
/**
* Creates a user for address book.
*/
public class CreateCommand extends Command {

public static final String COMMAND_WORD = "create";
private static boolean createIsSuccessful = false;

//TODO: update MESSAGE_USAGE
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
Expand All @@ -27,8 +30,8 @@ public class CreateCommand extends Command {
+ PREFIX_USERNAME + "username "
+ PREFIX_PASSWORD + "password ";

public static final String MESSAGE_SUCCESS = "New user added: %1$s";
public static final String MESSAGE_FAILURE = "User already exist!";
private static final String MESSAGE_SUCCESS = "New user added successfully!";
private static final String MESSAGE_FAILURE = "Username already exist.";

private final Accounts newAccount;

Expand All @@ -40,12 +43,21 @@ public CreateCommand(Accounts account) {
newAccount = account;

if (!UserAccountStorage.checkDuplicateUser(account.getUsername())) {
UserAccountStorage.addNewAccount(newAccount.getUsername(), newAccount.getPassword());
UserAccountStorage.addNewAccount(account.getUsername(), account.getPassword());
createIsSuccessful = true;
} else {
createIsSuccessful = false;
}
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
return new CommandResult(String.format(MESSAGE_SUCCESS));
requireNonNull(model);

if (createIsSuccessful == true) {
return new CommandResult(String.format(MESSAGE_SUCCESS));
} else {
return new CommandResult(String.format(MESSAGE_FAILURE));
}
}
}
19 changes: 14 additions & 5 deletions src/main/java/seedu/address/logic/commands/LoginCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PASSWORD;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_USERNAME;
Expand All @@ -10,12 +11,14 @@
import seedu.address.model.person.Accounts;
import seedu.address.storage.UserAccountStorage;

//@@author aspiringdevslog
/**
* Creates a user for address book.
*/
public class LoginCommand extends Command {

public static final String COMMAND_WORD = "login";
private static boolean loginIsSuccessful = false;

//TODO: update MESSAGE_USAGE
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
Expand All @@ -27,23 +30,29 @@ public class LoginCommand extends Command {
+ PREFIX_USERNAME + "username "
+ PREFIX_PASSWORD + "password ";

public static final String MESSAGE_SUCCESS = "Login successful!";
public static final String MESSAGE_FAILURE = "Login failed!";
private static final String MESSAGE_SUCCESS = "Login successful!";
private static final String MESSAGE_FAILURE = "Login failed!";
//TODO: throw exception message

/**
* Login
*/
public LoginCommand(Accounts account) {
if (UserAccountStorage.checkPasswordMatch(account.getUsername(), account.getPassword())) {
System.out.println(MESSAGE_SUCCESS);
loginIsSuccessful = true;
} else {
System.out.println(MESSAGE_FAILURE);
loginIsSuccessful = false;
}
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
return null;
requireNonNull(model);

if (loginIsSuccessful == true) {
return new CommandResult(String.format(MESSAGE_SUCCESS));
} else {
return new CommandResult(String.format(MESSAGE_FAILURE));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Accounts;

//@@author aspiringdevslog
/**
* Parses input arguments and creates a new AddCommand object
* Parses input arguments and creates a new CreateCommand object
*/
public class CreateCommandParser {

Expand All @@ -25,11 +26,9 @@ public CreateCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_USERNAME, PREFIX_PASSWORD);


String username = ParserUtil.parseUsername(argMultimap.getValue(PREFIX_USERNAME).get());
String password = ParserUtil.parsePassword(argMultimap.getValue(PREFIX_PASSWORD).get());


Accounts account = new Accounts(username, password);

return new CreateCommand(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Accounts;

//@@author aspiringdevslog
/**
* Parses input arguments and creates a new AddCommand object
*/
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/logic/security/Encrypt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seedu.address.logic.security;

//@@author aspiringdevslog

/**
* Encrypts data before saving
*/
public class Encrypt {

public static String encryptString(String plainString) {
return plainString.concat("encrypt123456");
}

public static String decryptString(String encryptedString) {
return encryptedString.replace("encrypt123456", "");
}
}
26 changes: 24 additions & 2 deletions src/main/java/seedu/address/storage/UserAccountStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.util.HashMap;

import seedu.address.logic.security.Encrypt;

//@@author aspiringdevslog

/**
* Storage of username and passwords
*/
Expand All @@ -12,12 +16,30 @@ public class UserAccountStorage {
public UserAccountStorage() {
}

/**
* @param username
* @param password
*/

public static void addNewAccount(String username, String password) {
userHashMap.put(username, password);
String encryptedPassword = Encrypt.encryptString(password);
userHashMap.put(username, encryptedPassword);
}

/**
* @param username
* @param password
* @return
*/
public static boolean checkPasswordMatch(String username, String password) {
return userHashMap.get(username).equals(password);
String encryptedPassword = Encrypt.encryptString(password);
/*
TODO: remove this line, temporary to see output.
System.out.print("Encrypted password: " + encryptedPassword +
" User entered: " + password + " Stored in hashmap: " + userHashMap.get(username) + " Decrypted password: "
+ Encrypt.decryptString(userHashMap.get(username)));
*/
return userHashMap.get(username).equals(encryptedPassword);
}

public static boolean checkDuplicateUser(String username) {
Expand Down

0 comments on commit e9bfd58

Please sign in to comment.