Ejemplo n.º 1
0
        private static ExpiredPassword.ChangePasswordResult ChangePasswordNUCP(string logonName, SecureString oldPassword, SecureString newPassword)
        {
            if (logonName == null || oldPassword == null || newPassword == null)
            {
                throw new ArgumentNullException();
            }
            string text  = string.Empty;
            string text2 = string.Empty;

            switch (OwaVdirConfiguration.Instance.LogonFormat)
            {
            case LogonFormats.FullDomain:
                ExpiredPassword.GetDomainUser(logonName, ref text, ref text2);
                break;

            case LogonFormats.PrincipalName:
                text  = NativeHelpers.GetDomainName();
                text2 = logonName;
                break;

            case LogonFormats.UserName:
                if (logonName.IndexOf("\\") == -1)
                {
                    text2 = logonName;
                    text  = NativeHelpers.GetDomainName();
                }
                else
                {
                    ExpiredPassword.GetDomainUser(logonName, ref text, ref text2);
                }
                break;
            }
            if (text == string.Empty || text2 == string.Empty)
            {
                return(ExpiredPassword.ChangePasswordResult.OtherError);
            }
            IntPtr intPtr  = IntPtr.Zero;
            IntPtr intPtr2 = IntPtr.Zero;

            try
            {
                intPtr  = Marshal.SecureStringToGlobalAllocUnicode(oldPassword);
                intPtr2 = Marshal.SecureStringToGlobalAllocUnicode(newPassword);
                uint num = ExpiredPassword.NetUserChangePassword(text, text2, intPtr, intPtr2);
                if (num != 0U)
                {
                    uint num2 = num;
                    if (num2 == 5U)
                    {
                        return(ExpiredPassword.ChangePasswordResult.LockedOut);
                    }
                    if (num2 == 86U)
                    {
                        return(ExpiredPassword.ChangePasswordResult.InvalidCredentials);
                    }
                    if (num2 != 2245U)
                    {
                        return(ExpiredPassword.ChangePasswordResult.OtherError);
                    }
                    return(ExpiredPassword.ChangePasswordResult.BadNewPassword);
                }
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(intPtr);
                }
                if (intPtr2 != IntPtr.Zero)
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(intPtr2);
                }
            }
            return(ExpiredPassword.ChangePasswordResult.Success);
        }
Ejemplo n.º 2
0
        private void ChangePassword()
        {
            SecureHtmlFormReader secureHtmlFormReader = new SecureHtmlFormReader(base.Request);

            secureHtmlFormReader.AddSensitiveInputName("oldPwd");
            secureHtmlFormReader.AddSensitiveInputName("newPwd1");
            secureHtmlFormReader.AddSensitiveInputName("newPwd2");
            SecureNameValueCollection secureNameValueCollection = null;

            try
            {
                if (secureHtmlFormReader.TryReadSecureFormData(out secureNameValueCollection))
                {
                    string       text          = null;
                    SecureString secureString  = null;
                    SecureString secureString2 = null;
                    SecureString secureString3 = null;
                    try
                    {
                        secureNameValueCollection.TryGetUnsecureValue("username", out text);
                        secureNameValueCollection.TryGetSecureValue("oldPwd", out secureString);
                        secureNameValueCollection.TryGetSecureValue("newPwd1", out secureString2);
                        secureNameValueCollection.TryGetSecureValue("newPwd2", out secureString3);
                        if (text != null && secureString != null && secureString2 != null && secureString3 != null)
                        {
                            if (!ExpiredPassword.SecureStringEquals(secureString2, secureString3))
                            {
                                this.reason = ExpiredPassword.ExpiredPasswordReason.PasswordConflict;
                            }
                            else
                            {
                                switch (ExpiredPassword.ChangePasswordNUCP(text, secureString, secureString2))
                                {
                                case ExpiredPassword.ChangePasswordResult.Success:
                                    this.reason          = ExpiredPassword.ExpiredPasswordReason.None;
                                    this.passwordChanged = true;
                                    break;

                                case ExpiredPassword.ChangePasswordResult.InvalidCredentials:
                                    this.reason = ExpiredPassword.ExpiredPasswordReason.InvalidCredentials;
                                    break;

                                case ExpiredPassword.ChangePasswordResult.LockedOut:
                                    this.reason = ExpiredPassword.ExpiredPasswordReason.LockedOut;
                                    break;

                                case ExpiredPassword.ChangePasswordResult.BadNewPassword:
                                    this.reason = ExpiredPassword.ExpiredPasswordReason.InvalidNewPassword;
                                    break;

                                case ExpiredPassword.ChangePasswordResult.OtherError:
                                    this.reason = ExpiredPassword.ExpiredPasswordReason.InvalidCredentials;
                                    break;
                                }
                            }
                        }
                    }
                    finally
                    {
                        secureString.Dispose();
                        secureString2.Dispose();
                        secureString3.Dispose();
                    }
                }
            }
            finally
            {
                if (secureNameValueCollection != null)
                {
                    secureNameValueCollection.Dispose();
                }
            }
        }