Example #1
0
 private void password_Leave(object sender, EventArgs e)
 {
     if (pwdHash || password.Text.StartsWith("@@"))
     {
         var hasher = new PasswordHasher("scouting.nl", password.Text);
         password.Text = hasher.GetHashedPassword();
         pwdHash = false;
         password.BackColor = Color.White;
     }
 }
Example #2
0
        /// <summary>
        /// Generate a hashed password based on the PwdHash algorithm
        /// </summary>
        /// <param name="siteAddress">
        /// A <see cref="System.String"/> representing the full URL of the site
        /// you would like to use the password for.
        /// </param>
        /// <param name="sitePassword">
        /// A <see cref="System.String"/> with the base password used for this
        /// site
        /// </param>
        /// <returns>
        /// A <see cref="System.String"/> containing the unique, strong password
        /// generated using an MD5 hash and the PwdHash algorithm to ensure a
        /// strong and hard-to-guess password
        /// </returns>
        public string GenerateHashedPassword(string siteAddress, string sitePassword)
        {
            // Validate parameters
            if (siteAddress == null)
                throw new ArgumentNullException("siteAddress",
                                                "Please specify a valid Site Address");
            if (siteAddress.Equals(string.Empty))
                throw new ArgumentException("Please specify a valid Site Address",
                                            "siteAddress");
            if (sitePassword == null)
                throw new ArgumentNullException("sitePassword",
                                                "Please specify a valid Site Password");
            if (sitePassword.Equals(string.Empty))
                throw new ArgumentException("Please specify a valid Site Password",
                                            "sitePassword");

            // Get the base domain from the given URI
            string domain = DomainExtractor.ExtractDomain(siteAddress);

            // Make sure the new domain isn't empty
            if (domain.Equals(string.Empty))
                throw new ArgumentException("Please specify a valid Site Address",
                                            "siteAddress");

            // Then, use it along with the site password to apply the PwdHash
            // algorithm.
            PasswordHasher hasher = new PasswordHasher(domain, sitePassword);
            string hashedPassword = hasher.GetHashedPassword();

            return hashedPassword;
        }