Compute() public static method

Computes the Hash code of a string and converts it into a Hex string.
public static Compute ( string input ) : string
input string The string.
return string
示例#1
0
        /// <summary>
        /// Tries to login a user directly through the provider.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>The correct UserInfo object, or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>username</b> or <b>password</b> are <c>null</c>.</exception>
        public UserInfo TryManualLogin(string username, string password)
        {
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            // Shortcut
            if (username.Length == 0)
            {
                return(null);
            }

            if (password.Length == 0)
            {
                return(null);
            }

            lock (this) {
                string     hash = Hash.Compute(password);
                UserInfo[] all  = GetUsers();
                foreach (UserInfo u in all)
                {
                    if (u.Active &&
                        //string.Compare(u.Username, username, false, System.Globalization.CultureInfo.InvariantCulture) == 0 &&
                        //string.Compare(((LocalUserInfo)u).PasswordHash, hash, false, System.Globalization.CultureInfo.InvariantCulture) == 0) {
                        string.CompareOrdinal(u.Username, username) == 0 &&
                        string.CompareOrdinal(((LocalUserInfo)u).PasswordHash, hash) == 0)
                    {
                        return(u);
                    }
                }
            }
            return(null);
        }
        /// <summary>
        /// Cvs the check old password.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param>
        protected void cvCheckOldPassword(object sender, ServerValidateEventArgs e)
        {
            string pwd = Hash.Compute(txtBoxOldPassword.Text);

            if (pwd == GlobalSettings.GetMasterPassword())
            {
                if ((txtNewPassword.Text.Length != 0) && (txtNewPassword.Text != null))
                {
                    e.IsValid = true;
                }
                else
                {
                    e.IsValid = false;
                    ((CustomValidator)sender).ErrorMessage = Properties.Messages.PasswordEmpty;
                }
            }
            else
            {
                e.IsValid = false;
                ((CustomValidator)sender).ErrorMessage = Properties.Messages.WrongPassword;
            }
        }
示例#3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            GlobalSettings.SetMasterPassword(Hash.Compute(txtReNewPwd.Text));
            newAdminPassForm.Visible    = false;
            newAdminPassOk.Visible      = true;
            lblResult.CssClass          = "resultok";
            lblResult.Text              = Properties.Messages.ConfigSaved;
            lnkMainRedirect.Visible     = true;
            lnkMainRedirect.NavigateUrl = "~/";
            lblDescriptionPwd.Visible   = false;
            lblNewPwd.Visible           = false;
            txtNewPwd.Visible           = false;
            lblReNewPwd.Visible         = false;
            txtReNewPwd.Visible         = false;
            BtnSave.Visible             = false;
        }
示例#4
0
        /// <summary>
        /// Modifies a User.
        /// </summary>
        /// <param name="user">The Username of the user to modify.</param>
        /// <param name="newDisplayName">The new display name (can be <c>null</c>).</param>
        /// <param name="newPassword">The new Password (<c>null</c> or blank to keep the current password).</param>
        /// <param name="newEmail">The new Email address.</param>
        /// <param name="newActive">A value indicating whether the account is active.</param>
        /// <returns>The correct <see cref="T:UserInfo"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>user</b> or <b>newEmail</b> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>newEmail</b> is empty.</exception>
        public UserInfo ModifyUser(UserInfo user, string newDisplayName, string newPassword, string newEmail, bool newActive)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (newEmail == null)
            {
                throw new ArgumentNullException("newEmail");
            }

            if (newEmail.Length == 0)
            {
                throw new ArgumentException("New Email cannot be empty", "newEmail");
            }

            lock (this) {
                LocalUserInfo local = LoadLocalInstance(user);
                if (local == null)
                {
                    return(null);
                }

                UserInfo[]       allUsers = GetUsers();
                UsernameComparer comp     = new UsernameComparer();

                usersCache = null;

                for (int i = 0; i < allUsers.Length; i++)
                {
                    if (comp.Compare(allUsers[i], user) == 0)
                    {
                        LocalUserInfo result = new LocalUserInfo(user.Username, newDisplayName, newEmail,
                                                                 newActive, user.DateTime, this,
                                                                 string.IsNullOrEmpty(newPassword) ? local.PasswordHash : Hash.Compute(newPassword));
                        result.Groups = allUsers[i].Groups;
                        allUsers[i]   = result;
                        DumpUsers(allUsers);
                        return(result);
                    }
                }
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Adds a new User.
        /// </summary>
        /// <param name="username">The Username.</param>
        /// <param name="displayName">The display name (can be <c>null</c>).</param>
        /// <param name="password">The Password.</param>
        /// <param name="email">The Email address.</param>
        /// <param name="active">A value specifying whether or not the account is active.</param>
        /// <param name="dateTime">The Account creation Date/Time.</param>
        /// <returns>The correct <see cref="T:UserInfo"/> object or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <b>username</b>, <b>password</b> or <b>email</b> are <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <b>username</b>, <b>password</b> or <b>email</b> are empty.</exception>
        public UserInfo AddUser(string username, string displayName, string password, string email, bool active, DateTime dateTime)
        {
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }

            if (username.Length == 0)
            {
                throw new ArgumentException("Username cannot be empty", "username");
            }

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            if (password.Length == 0)
            {
                throw new ArgumentException("Password cannot be empty", "password");
            }

            if (email == null)
            {
                throw new ArgumentNullException("email");
            }

            if (email.Length == 0)
            {
                throw new ArgumentException("Email cannot be empty", "email");
            }

            lock (this) {
                if (UserExists(new UserInfo(username, displayName, "", true, DateTime.Now, this)))
                {
                    return(null);
                }

                BackupUsersFile();

                StringBuilder sb = new StringBuilder();
                sb.Append(username);
                sb.Append("|");
                sb.Append(Hash.Compute(password));
                sb.Append("|");
                sb.Append(email);
                sb.Append("|");
                sb.Append(active ? "ACTIVE" : "INACTIVE");
                sb.Append("|");
                sb.Append(dateTime.ToString("yyyy'/'MM'/'dd' 'HH':'mm':'ss"));
                // ADMIN|USER no more used in version 3.0
                //sb.Append("|");
                //sb.Append(admin ? "ADMIN" : "USER");
                if (!string.IsNullOrEmpty(displayName))
                {
                    sb.Append("|");
                    sb.Append(displayName);
                }
                sb.Append("\r\n");
                File.AppendAllText(GetFullPath(UsersFile), sb.ToString());

                usersCache = null;

                return(new LocalUserInfo(username, displayName, email, active, dateTime, this, Hash.Compute(password)));
            }
        }
示例#6
0
 /// <summary>
 /// Gets a valid and consistent GUID for RSS items.
 /// </summary>
 /// <param name="item">The item name, for example the page name.</param>
 /// <param name="editDateTime">The last date/time the item was modified.</param>
 /// <returns>The GUID.</returns>
 private string GetGuid(string item, DateTime editDateTime)
 {
     return(Hash.Compute(item + editDateTime.ToString("yyyyMMddHHmmss")));
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblResult.CssClass = "";
            lblResult.Text     = "";

            Page.Validate();

            if (!Page.IsValid)
            {
                return;
            }

            Log.LogEntry("Wiki Configuration change requested", EntryType.General, SessionFacade.CurrentUsername, currentWiki);

            // Save general configuration
            GlobalSettings.ContactEmail = txtContactEmail.Text;
            GlobalSettings.SenderEmail  = txtSenderEmail.Text;
            GlobalSettings.ErrorsEmails = GetErrorsEmails();
            GlobalSettings.SmtpServer   = txtSmtpServer.Text;

            txtSmtpPort.Text = txtSmtpPort.Text.Trim();
            if (txtSmtpPort.Text.Length > 0)
            {
                GlobalSettings.SmtpPort = int.Parse(txtSmtpPort.Text);
            }
            else
            {
                GlobalSettings.SmtpPort = -1;
            }
            if (txtUsername.Text.Length > 0)
            {
                GlobalSettings.SmtpUsername = txtUsername.Text;
                GlobalSettings.SmtpPassword = txtPassword.Text;
            }
            else
            {
                GlobalSettings.SmtpUsername = "";
                GlobalSettings.SmtpPassword = "";
            }
            GlobalSettings.SmtpSsl = chkEnableSslForSmtp.Checked;

            // Save security configuration
            GlobalSettings.UsernameRegex = txtUsernameRegEx.Text;
            GlobalSettings.PasswordRegex = txtPasswordRegEx.Text;

            GlobalSettings.MaxFileSize = int.Parse(txtMaxFileSize.Text);
            LoggingLevel level = LoggingLevel.AllMessages;

            if (rdoAllMessages.Checked)
            {
                level = LoggingLevel.AllMessages;
            }
            else if (rdoWarningsAndErrors.Checked)
            {
                level = LoggingLevel.WarningsAndErrors;
            }
            else if (rdoErrorsOnly.Checked)
            {
                level = LoggingLevel.ErrorsOnly;
            }
            else
            {
                level = LoggingLevel.DisableLog;
            }
            GlobalSettings.LoggingLevel = level;
            GlobalSettings.MaxLogSize   = int.Parse(txtMaxLogSize.Text);

            // Save advanced configuration
            GlobalSettings.DisableAutomaticVersionCheck = !chkEnableAutomaticUpdateChecks.Checked;
            GlobalSettings.EnableViewStateCompression   = chkEnableViewStateCompression.Checked;
            GlobalSettings.EnableHttpCompression        = chkEnableHttpCompression.Checked;

            // Save master password
            if (txtBoxOldPassword.Text != "" && txtBoxOldPassword.Text != null && txtBoxOldPassword.Text.Length != 0)
            {
                if (txtNewPassword.Text.Length != 0)
                {
                    if (Hash.Compute(txtNewPassword.Text) == Hash.Compute(txtReNewPassword.Text))
                    {
                        GlobalSettings.SetMasterPassword(Hash.Compute(txtNewPassword.Text));
                    }
                }
            }

            lblResult.CssClass = "resultok";
            lblResult.Text     = Properties.Messages.ConfigSaved;
        }