Пример #1
0
        //create new SessionToken
        private static string GetNewSessionToken(string userName)
        {
            string SessionAuthToken = Guid.NewGuid().ToString();

            Uporabniki Uporabnik = DAOService.GetUporabnik(userName);

            AuthSession authSession = new AuthSession()
            {
                SessionToken   = SessionAuthToken,
                UporabnikKLJ   = Uporabnik.UporabnikKLJ,
                SessionTimeOut = 1800,
                Issued         = DateTime.Now,
                Expired        = DateTime.Now.AddSeconds(1800)
            };

            DAOService.SaveNewSession(authSession);

            return(SessionAuthToken);
        }
Пример #2
0
        //validate user in Active Directory(AD)
        private static bool ValidateUserOrRIFID(string userNameOrRIFID)
        {
            bool   valid  = false;
            string domain = "novakbm.nkbm.si";

            try
            {
                //we try to check userName in AD
                try
                {
                    using (var domainContext = new PrincipalContext(ContextType.Domain, domain))
                    {
                        using (UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, userNameOrRIFID))
                        {
                            return(true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //TODO
                }


                //we try to check if RFID is valid
                #pragma warning disable CS0162 // Unreachable code detected
                if (DAOService.GetUporabnik(userNameOrRIFID).RFID == userNameOrRIFID)
                {
                    return(true);
                }
                #pragma warning restore CS0162 // Unreachable code detected
            }
            catch (Exception ex)
            {
                //TODO
            }


            return(valid);
        }