Esempio n. 1
0
        public ResetPassword(MySqlConnection con)
        {
            while (true)
            {
                Connection = con;

                Console.WriteLine("lets reset your password\nFirst enter your trainer name: ");
                TrainerName = Console.ReadLine();

                string lookupEmailByName = "SELECT email FROM sql3346222.userCredentials WHERE(TrainerName = '" + TrainerName + "');";
                string returnedEmail     = "0";

                Console.WriteLine("Enter the email attached to your account: ");
                EnteredEmail = Console.ReadLine();

                con.Open();
                MySqlCommand    query = new MySqlCommand(lookupEmailByName, con);
                MySqlDataReader rdr   = query.ExecuteReader();

                //reading returned query
                while (rdr.Read())
                {
                    returnedEmail = rdr[0].ToString();
                }
                rdr.Close();
                con.Close();

                //if an email is returned from DB this is skipped
                if (returnedEmail.Length <= 1)
                {
                    string newUser;
                    Console.WriteLine("No email found or user name incorrect!\nPlease try again or create new user");
                    Console.WriteLine("Would you like to make a new account?(y/n)");
                    newUser = Console.ReadLine();
                    while (true)
                    {
                        //Choice if user is new, takes them to create user
                        if (newUser.ToLower().Equals("y"))
                        {
                            var backToMakeNewAccount = new UserAuthAndLogin();
                            break;
                        }

                        //Choice if user enters, N not a new user, prompts login
                        if (newUser.ToLower().Equals("n"))
                        {
                            break;
                        }

                        //if something other than y or n is entered user is prompted with choice again
                        Console.WriteLine("Invalid choice! Please type y or n");
                        Console.WriteLine("Make new account? (y/n)");
                        newUser = Console.ReadLine();
                    }
                }

                while (true)
                {
                    if (returnedEmail == EnteredEmail)
                    {
                        var emailVerificationForReset = new EmailValidation(returnedEmail);
                        if (emailVerificationForReset.EmailIsValid == true)
                        {
                            Console.WriteLine("Lets reset your password...");
                            MakeNewPassword();
                            var backToLogin = new UserAuthAndLogin();
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Emails do not match! Let's try this again");
                        break;
                    }
                }
                break;
            }
        }
Esempio n. 2
0
        private void DoUserCreation(MySqlConnection con)
        {
            //Database only take VARCHAR(100) to save on space, user inputs need to be less than 100 chars
            while (true)
            {
                //Makes sure new user name is less than 100 chars
                Console.WriteLine("Enter new desired trainer name");
                TrainerName = Console.ReadLine();
                if (TrainerName.Length > 50)
                {
                    Console.WriteLine("Trainer name is to long, enter a shorter one!");
                }
                else
                {
                    if (UserNameValidation(TrainerName, con))
                    {
                        if (!Grand.alphaNumeric.IsMatch(TrainerName))
                        {
                            Console.WriteLine("Trainer names can contain only letters, numbers, and underscores!");
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("That trainer name is already taken! Try another username.");
                    }
                }
            }

            while (true)
            {
                //Makes sure new user name is less than 100 chars
                Console.WriteLine("Enter new Password");
                Password = Console.ReadLine();
                if (Password.Length > 50)
                {
#warning This input is not yet being vetted to mitigate SQL injections.
                    Console.WriteLine("Password is to long, enter a shorter one!");
                }
                else
                {
                    break;
                }
            }

            while (true)
            {
                //Makes sure new Email is less than 100 chars
                Console.WriteLine("Enter Email address");
                Email = Console.ReadLine();
                if (Password.Length > 99)
                {
                    Console.WriteLine("Email is to long, choose a different one!");
                }
                else
                {
                    var EmailSetup = new EmailValidation(Email);
                    //validates if the entered Email is in supported format
                    if (EmailSetup.EmailIsInCorrectForm == false)
                    {
                        Console.WriteLine("Email is in invalid form! Try again");
                    }
                    if (EmailSetup.EmailIsValid == false)
                    {
                        Console.WriteLine("Email could not be validated! Try again");
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Password = UserPasswordHash(Password);
            InsertDBcredentials(TrainerName, Password, Email, con);
        }
        public ResetPassword(MySqlConnection con)
        {
            while (true)
            {
                Connection = con;

                Console.WriteLine("Lets reset your password.\nFirst enter your trainer name: ");
                while (true)
                {
                    TrainerName = Console.ReadLine().Trim();
                    if (!Grand.alphaNumeric.IsMatch(TrainerName))
                    {
                        Console.WriteLine("Trainer names can contain only letters, numbers, and underscores!");
                    }
                    else
                    {
                        break;
                    }
                }
                string lookupEmailByName = "SELECT email FROM sql3346222.userCredentials WHERE(TrainerName = @Username);";
                string returnedEmail     = "0";

                Console.WriteLine("Enter the email attached to your account: ");
                EnteredEmail = Console.ReadLine().Trim();

                con.Open();
                MySqlCommand query = new MySqlCommand(lookupEmailByName, con);
                query.Parameters.Add(@"@Username", MySqlDbType.VarChar);
                query.Parameters[@"@Username"].Value = TrainerName;
                MySqlDataReader rdr = query.ExecuteReader();

                //reading returned query
                while (rdr.Read())
                {
                    returnedEmail = rdr[0].ToString();
                }
                rdr.Close();
                con.Close();

                //if an email is returned from DB this is skipped
                if (returnedEmail.Length <= 1)
                {
                    string newUser;
                    Console.WriteLine("No email found or user name incorrect!\nPlease try again or create new user");
                    Console.WriteLine("Would you like to make a new account? (Y/N)");
                    while (true)
                    {
                        newUser = Console.ReadLine().Trim();
                        //Choice if user is new, takes them to create user
                        if (Grand.yes.IsMatch(newUser))
                        {
                            var backToMakeNewAccount = new UserAuthAndLogin();
                            break;
                        }
                        //Choice if user enters, N not a new user, prompts login
                        else if (Grand.no.IsMatch(newUser))
                        {
                            break;
                        }

                        //if something other than y or n is entered user is prompted with choice again
                        Console.WriteLine("Invalid choice! Please type y or n");
                        Console.WriteLine("Make new account? (Y/N)");
                    }
                }

                while (true)
                {
                    if (returnedEmail == EnteredEmail)
                    {
                        var emailVerificationForReset = new EmailValidation(returnedEmail);
                        if (emailVerificationForReset.EmailIsValid == true)
                        {
                            Console.WriteLine("Lets reset your password...");
                            MakeNewPassword();
                            var backToLogin = new UserAuthAndLogin();
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Emails do not match! Let's try this again");
                        break;
                    }
                }
                break;
            }
        }