Ejemplo n.º 1
0
 private async void btnChange_Click(object sender, EventArgs e)
 {
     if (IsValidControls())
     {
         try
         {
             string oldPassword = txtCurrent.Text.Trim();
             if (EncryptionData.ValidateEncryptedData(oldPassword, oUser.Password))
             {
                 //Change the current password
                 oUser.Password = txtNew.Text.Trim();
                 if (await userdata.ChangePassword(oUser))
                 {
                     Logger.WriteToFile(Logger.FullName, "Changed password");
                     MessageBox.Show("Password has been successfully changed", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Unable to change password", "Change password", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 }
             }
             else
             {
                 MessageBox.Show("Invalid Password. Please Enter the right password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Confirms whether the license the user is inserting is valid or not.
        /// </summary>
        /// <param name="license">The license you want to apply</param>

        public async Task <bool> ConfirmLicense(LicenseModel license)
        {
            var data = await ReadLicense();

            if (data != null)
            {
                return(EncryptionData.ValidateEncryptedData(license.LicenseKey, data.LicenseKey));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> LogUser(UserModel user, LoginDetails loginUser)
        {
            //Select the user from the database
            var userFromDatabase = await SelectUser(user.Name);

            //Check if the user name exist
            if (userFromDatabase == null)
            {
                return(false);
            }
            //Compare the password
            if (!EncryptionData.ValidateEncryptedData(user.Password, userFromDatabase.Password))
            {
                return(false);
            }

            loginUser(userFromDatabase);
            return(true);
        }
Ejemplo n.º 4
0
        private async void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                if (isConfirmUser)
                {
                    //Do for confirm user
                    if (isValidConfirmUser())
                    {
                        lblWait.Visible = true;


                        string username = confirmUser1.txtUserName.Text.Trim();
                        oUser = await user.SelectUser(username);

                        if (oUser != null)
                        {
                            //Show the security question
                            lblWait.Visible = false;
                            //Set the question
                            securityQuestion1.lblQuestion.Text = GetQuestion(oUser.Question);
                            securityQuestion1.BringToFront();
                            isConfirmUser = false;
                            isQuestion    = true;
                            return;
                        }
                        else
                        {
                            lblWait.Visible = false;
                            MessageBox.Show("Invalid Username. You are not a registered user", "Invalid User", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }


                if (isQuestion)
                {
                    //Do for question.
                    if (isValidQuestion())
                    {
                        lblWait.Visible = true;
                        string userAnswer = securityQuestion1.txtAnswer.Text.Trim().ToLower();
                        if (EncryptionData.ValidateEncryptedData(userAnswer, oUser.Answer))
                        {
                            //Move to the next step
                            lblWait.Visible = false;
                            isQuestion      = false;
                            isPassword      = true;
                            userPassword1.BringToFront();
                            btnNext.Text = "Change";
                            return;
                        }
                        else
                        {
                            lblWait.Visible = false;
                            MessageBox.Show("Invalid Answer. Please provide a valid answer.", "Invalid Answer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }


                if (isPassword)
                {
                    //Change the user's password
                    if (isValidPassword())
                    {
                        string newPassword = userPassword1.txtPassword.Text.Trim();
                        oUser.Password = newPassword;
                        if (await user.ChangePassword(oUser))
                        {
                            Logger.WriteToFile(oUser.FullName, "successfully changed password");
                            MessageBox.Show("Password has been successfully changed", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Unable to change password", "Please try again", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }