Пример #1
0
        /// <summary>
        /// Authenticate User for first login
        /// </summary>
        /// <param name="Program_Code"> Program Code </param>
        /// <param name="Domain_Name"> Domain Name </param>
        /// <param name="User_EmailID"> User EmailID </param>
        /// <param name="User_Password"> User Password </param>
        /// <returns>Authenticate</returns>
        public AccountModal AuthenticateUser(string Program_Code, string Domain_Name, string User_EmailID, string User_Password)
        {
            AccountModal accountModal = new AccountModal();

            try
            {
                ////Decrypt Data
                Program_Code = DecryptStringAES(Program_Code);
                Domain_Name  = DecryptStringAES(Domain_Name);
                User_EmailID = DecryptStringAES(User_EmailID);

                Authenticate authenticate = new Authenticate();
                ////Check whether Login is valid or not
                authenticate = isValidLogin(Program_Code, Domain_Name, User_EmailID, User_Password);

                if (authenticate.UserMasterID > 0)
                {
                    /*Valid User then generate token and save to the database */

                    ////Generate Token
                    string token = generateAuthenticateToken(authenticate.ProgramCode, authenticate.Domain_Name, authenticate.AppID);

                    authenticate.Token = token;

                    //Save User Token
                    SaveUserToken(authenticate);

                    //Serialise Token & save token to Cache
                    string jsonString = JsonConvert.SerializeObject(authenticate);

                    RedisCacheService radisCacheService = new RedisCacheService(Cache);
                    radisCacheService.Set(Cache, authenticate.Token, jsonString);

                    accountModal.Message = "Valid user";

                    ////Double encryption: We are doing encryption of encrypted token
                    accountModal.Token       = Encrypt(token);
                    accountModal.IsValidUser = true;
                    accountModal.FirstName   = authenticate.FirstName;
                    accountModal.LastName    = authenticate.LastName;
                    accountModal.UserEmailID = User_EmailID;
                }
                else
                {
                    //Wrong Username or password
                    accountModal.Message     = "Invalid username or password";
                    accountModal.Token       = "";
                    accountModal.IsValidUser = false;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return(accountModal);
        }
Пример #2
0
        public static Authenticate GetAuthenticateDataFromTokenCache(IDistributedCache cache, string token)
        {
            Authenticate authenticate = new Authenticate();

            try
            {
                // var cach=cach.get
                RedisCacheService cacheService = new RedisCacheService(cache);
                string            data         = cacheService.Get(cache, token);
                authenticate = JsonConvert.DeserializeObject <Authenticate>(data);
            }
            catch (Exception)
            {
                throw;
            }

            return(authenticate);
        }
Пример #3
0
        /// <summary>
        /// Get data from token (Radish)
        /// </summary>
        /// <param name="_radisCacheServerAddress"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Authenticate GetAuthenticateDataFromToken(string _radisCacheServerAddress, string token)
        {
            Authenticate authenticate = new Authenticate();

            try
            {
                RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                //if (cacheService.Exists(token))
                //{
                //    string _data = cacheService.Get(token);
                //    authenticate = JsonConvert.DeserializeObject<Authenticate>(_data);
                //}
            }
            catch (Exception)
            {
                throw;
            }

            return(authenticate);
        }