Ejemplo n.º 1
0
        public int ChangePwd(string oldPwd, string newPwd)
        {
            try
            {
                byte[] realUserPwd = manager.GetPassword(Thread.CurrentPrincipal.Identity.Name);

                byte[] userPassword = new SHA1Managed().ComputeHash(
                    ASCIIEncoding.ASCII.GetBytes(oldPwd));

                if (!Convert.ToBase64String(userPassword).Equals
                        (Convert.ToBase64String(realUserPwd)))
                {
                    return(-1);
                }

                manager.ChangeUserPassword(Thread.CurrentPrincipal.Identity.Name,
                                           new SHA1Managed().ComputeHash(ASCIIEncoding.ASCII.GetBytes(newPwd)));

                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (tbxPassword1.Text != tbxPassword2.Text)
            {
                MessageBox.Show(SR.PasswordsMustMatch);
                return;
            }

            byte[] password = hashProvider.CreateHash(Encoding.Unicode.GetBytes(tbxPassword1.Text));

            if (editMode)
            {
                userRoleMgr.ChangeUserPassword(tbxUser.Text, password);
            }
            else if (userRoleMgr.UserExists(tbxUser.Text))
            {
                MessageBox.Show(SR.UserAlreadyExists);
                return;
            }
            else
            {
                userRoleMgr.CreateUser(tbxUser.Text, password);
            }

            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 3
0
        public void ChangePassword()
        {
            byte[] password = ASCIIEncoding.ASCII.GetBytes("zab123");
            manager.CreateUser(userName, password);

            byte[] newPassword = ASCIIEncoding.ASCII.GetBytes("5678901234");
            manager.ChangeUserPassword(userName, newPassword);

            DataSet ds = GetPassword(userName);

            Assert.AreEqual(newPassword.Length, ((byte[])ds.Tables[0].Rows[0]["Password"]).Length);

            manager.DeleteUser(userName);
        }
Ejemplo n.º 4
0
 private void ChangeUserPasswordDelegate(params object[] methodParams)
 {
     manager.ChangeUserPassword((string)methodParams[0], (byte[])methodParams[1]);
 }