public string GenerateAuthorizationToken(Guid userId)
        {
            string expiration = DateTime.Now.AddMinutes(EXPIRATION_MINUTES).ToString();

            string publicKey = ConfigurationManager.AppSettings["PublicKey"];

            string tokenString = string.Format("{0}|{1}|{2}", userId, expiration, publicKey);

            string encryptedToken = m_Encryptor.EncryptValue(tokenString);

            var hash = m_HashProvider.GenerateHash(encryptedToken, encryptedToken, publicKey);

            var token = string.Format("{0}|{1}", encryptedToken, hash);

            return(token);
        }
Exemplo n.º 2
0
        private string GetUserPasswordHash(string password, Guid salt)
        {
            string publicKey = ConfigurationManager.AppSettings["PublicKey"];

            string passwordHash = m_HashProvider.GenerateHash(password, salt.ToString(), publicKey);

            return(passwordHash);
        }
        public AuthenticationToken Authenticate(string login, string password, bool isWindows)
        {
            Guid guid;
            Guid existingGuid;
            var  guidExists = _sessionManager.TryGetGuid(login, out existingGuid);

            if (!_sessionManager.Authenticate(login, password, isWindows, out guid))
            {
                return(null);
            }
            if (guidExists)
            {
                _tokenLifetimes.Remove(existingGuid);
            }
            var salt       = Guid.NewGuid();
            var hash       = _hashProvider.GenerateHash(guid, salt);
            var hashString = GetHashString(hash);

            if (!_tokenLifetimes.ContainsKey(guid))
            {
                _tokenLifetimes.Add(guid, GetLifeTime());
            }
            return(new AuthenticationToken(hashString, salt));
        }
Exemplo n.º 4
0
 private string GenerateHash(string password)
 {
     return(_hashProvider.GenerateHash(password));
 }