Exemplo n.º 1
0
        public string Login(LoginDTO dto)
        {
            try
            {
                _log.Info($"Login: {dto.Username}");

                using (var context = new PrincipalContext(ContextType.Domain, "TTINT", null, ContextOptions.Negotiate, null, null))
                {
                    using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, dto.Username))
                    {
                        if (user != null)
                        {
                            var password = LoginDTO.Decrypt(dto.PasswordBytes);

                            if (context.ValidateCredentials(dto.Username, password))
                            {
                                _log.Info($"...{user} successful login :-)");
                                return("SUCCESS");
                            }
                        }

                        _log.Info($"...'{user}' unsuccessful login :-(");
                        return("FAILURE");
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw;
            }
        }