Exemplo n.º 1
0
        /* TODO:
         * Write a modified object's changed to BigQuery via DataAccess Layer
         *     (method should have a way of checking whether the class object changed during runtime
         *     to avoid redundant writing. Use a changed boolean to implement this)
         * Should not call DataAccess update() if did not change
         *  Returns: void */
        public void update(UserAccount userAccount)
        {
            // Checking if user account exists
            UserAccount retrievedUser = getUsingID(userAccount.AccountID);

            if (retrievedUser == null) // Checks if user already exists
            {
                Console.WriteLine("User Account does not exist.");
                return;
                //return new OkObjectResult("User Account does not exist");
            }
            else
            {
                // TODO: Need to add password service and salt/hash

                // Checks for Password Minimum Requirements
                if (PasswordService.CheckMinReqPassword(userAccount.PasswordHash) == false)
                {
                    Console.WriteLine("Password does not meet minimum requirements.");
                    return;
                }

                // Checking if Email is a valid Email Address
                if (!EmailService.IsValidEmailAddress(userAccount.EmailAddress.ToLower())) // Checks for valid email address
                {
                    //return new BadRequestObjectResult("Invalid Email address");
                    return;
                }

                // Checking if username already exists
                var retrievedUser2 = getUsingUsername(userAccount.AccountUsername);
                if (retrievedUser2 != null) // Checks if user already exists
                {
                    Console.WriteLine("Username already exists");
                    return;
                    //return new OkObjectResult("User already exists");
                }

                // Salts and hashes password for security concerns when storing to the database
                byte[] passwordSalt   = PasswordService.GenerateSalt();
                string passwordHashed = PasswordService.HashPassword(userAccount.PasswordHash, passwordSalt);

                userAccount.PasswordSalt = passwordSalt;
                userAccount.PasswordHash = passwordHashed;

                // If all the checks are passed then writeUserAccount to database
                // with newlyCreated bool = false and changed bool = true
                this.UserAccountDataAccess.update(serialize(userAccount));
                return;
                //return new OkObjectResult("Account successfully updated");
            }
        }
Exemplo n.º 2
0
        /*
         * Use DataAccess Layer to write a NEWLY CREATED object into BigQuery
         *  Params: userAccount - UserAccount object for inserted user account
         *  Returns: int -
         *      0 : Account Creation Success
         *      1 : Invalid or taken email
         *      2 : Username taken
         *      3 : Password too weak
         */
        public int write(UserAccount userAccount)
        {
            bool emailTaken = getUsingEmail(userAccount.EmailAddress) != null;

            // Checking if Email is a valid Email Address
            if (!EmailService.IsValidEmailAddress(userAccount.EmailAddress.ToLower()) || emailTaken) // Checks for valid email address
            {
                return(1);
            }

            // Checking if username already exists
            var retrievedUser = getUsingUsername(userAccount.AccountUsername);

            if (retrievedUser != null) // Checks if user already exists
            {
                Console.WriteLine("Username already exists.");
                return(2);
            }

            // Checks for Password Minimum Requirements
            if (PasswordService.CheckMinReqPassword(userAccount.PasswordHash) == false)
            {
                Console.WriteLine("Password does not meet minimum requirements.");
                return(3);
            }

            // Salts and hashes password for security concerns when storing to the database
            byte[] passwordSalt   = PasswordService.GenerateSalt();
            string passwordHashed = PasswordService.HashPassword(userAccount.PasswordHash, passwordSalt);

            userAccount.PasswordSalt = passwordSalt;
            userAccount.PasswordHash = passwordHashed;

            // If all the checks are passed then writeUserAccount to database
            this.UserAccountDataAccess.write(serialize(userAccount));
            return(0);
        }