Пример #1
0
        public void CanEncryptSha256Test()
        {
            var encryptor = new DataEncryptor();
            string input = "password123";
            string output = encryptor.GetSha256String(input);

            var sha256 = new SHA256CryptoServiceProvider();

            var data = Encoding.UTF8.GetBytes(input);
            var sha256data = sha256.ComputeHash(data);

            var properOutput = Convert.ToBase64String(sha256data);


            Assert.AreEqual( properOutput, output);  
        }
Пример #2
0
        public string ValidatePassword(string input)
        {
            if (!IsNotEmpty(input)) 
                throw new Exception("Input is empty!"); //throw exception if not proper

            var passwordLength = Properties.Settings.Default.PasswordLength;
            if (input.Length < passwordLength) 
                throw new Exception("Password must contain at least: " + passwordLength + "characters");

            //put here other password restrictions if needed

            //----------------

            //converting data into hashed password
            var encryptor = new DataEncryptor();
            var returnInput = encryptor.GetSha256String(input);

            return returnInput;
        }