Exemplo n.º 1
0
        //Validates Password, if Password is false gives option to reset Password
        public Boolean Validate(string userName, string pass, MySqlConnection con)
        {
            var lookupByName    = "SELECT `UserID`,Password FROM sql3346222.userCredentials WHERE(TrainerName = '" + userName + "');";
            var correctPassword = string.Empty;

            //opens new DB Connection with MySql and pulls hashed Password from userCredentials table
            con.Open();
            var cmd = new MySqlCommand(lookupByName, con);

            using (var rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    UserID          = Convert.ToInt32(rdr[0].ToString());
                    correctPassword = rdr[1].ToString();
                }
            }
            con.Close();

            if (UserID == 0)
            {
                Console.WriteLine("account not found!");
                return(false);
            }

            var sendToHashPasswordAlg = new HashingAlg(pass);
            var attemptedPassword     = sendToHashPasswordAlg.getHash();

            correctPassword = sendToHashPasswordAlg.reomveSecret(correctPassword);

            //checks the hashed Password the user entered agaisnt the hashedpass from DB
            if (correctPassword == attemptedPassword)
            {
                TrainerName = userName;
                Console.WriteLine("Welcome " + userName);
                Console.WriteLine("-------------------------------------------------------------------");
                return(true);
            }
            else //failed login attempt
            {
                Console.WriteLine("Username or Password incorrect! Please try again!");

                while (true)
                {
                    Console.WriteLine("Do you need to reset your Password? (Y/N)");
                    string resetPasswrodYorN = Console.ReadLine().Trim();
                    if (Grand.yes.IsMatch(resetPasswrodYorN))
                    {
                        var reset = new ResetPassword(con);
                        return(true);
                    }
                    else if (Grand.no.IsMatch(resetPasswrodYorN))
                    {
                        return(false);
                    }

                    Console.WriteLine("Invalid choice, please eneter y to reset Password or n to reattempt login!");
                }
            }
        }
Exemplo n.º 2
0
        private void MakeNewPassword()
        {
            string newPass;

            Console.WriteLine("Enter new password: "******"UPDATE sql3346222.userCredentials SET Password=(@Password)" +
                                    " WHERE TrainerName = (@Username);";
            //execute the query
            MySqlCommand query = new MySqlCommand(plainTextQuery, Connection);

            query.Parameters.Add(@"@Password", MySqlDbType.Text);
            query.Parameters[@"@Password"].Value = Hashedpass;
            query.Parameters.Add(@"@Username", MySqlDbType.VarChar);
            query.Parameters[@"@Username"].Value = TrainerName;
            MySqlDataReader rdr = query.ExecuteReader();

            while (rdr.Read())
            {
                Console.WriteLine(rdr[0] + " -- " + rdr[1]);
            }
            rdr.Close();
            Connection.Close();

            Console.WriteLine("Password reset!");
        }
Exemplo n.º 3
0
        //This is a private helper method that uses hashing alg to hash the nwe Password
        public string UserPasswordHash(string thePass)
        {
            string Hashedpass;
            var    sendToHashPasswordAlg = new HashingAlg(thePass);

            Hashedpass = sendToHashPasswordAlg.getHash();
            Hashedpass = sendToHashPasswordAlg.addSecret(Hashedpass);
            return(Hashedpass);
        }