Exemplo n.º 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(radisCacheServerAddress);
                    radisCacheService.Set(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)
            {
                throw;
            }
            finally
            {
            }

            return(accountModal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Validate Program Code
        /// </summary>
        /// <param name="Programcode"></param>
        /// <param name="Domainname"></param>
        public bool validateProgramCode(string Programcode, string Domainname)
        {
            bool isValid = false;


            DataSet ds = new DataSet();

            try
            {
                Programcode = DecryptStringAES(Programcode);
                Domainname  = DecryptStringAES(Domainname);

                conn.Open();
                MySqlCommand cmd = new MySqlCommand("SP_validateProgramCode", conn)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@Program_code", Programcode);
                cmd.Parameters.AddWithValue("@Domain_name", Domainname);
                //isValid = Convert.ToBoolean(cmd1.ExecuteScalar());
                MySqlDataAdapter da = new MySqlDataAdapter(cmd)
                {
                    SelectCommand = cmd
                };
                da.Fill(ds);
                if (ds != null && ds.Tables[0] != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        bool status = Convert.ToBoolean(ds.Tables[0].Rows[0]["Return"]);
                        isValid = status;

                        if (status)
                        {
                            string ConnectionString  = ds.Tables[0].Rows[0]["ConnectionString"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[0]["ConnectionString"]);
                            string ProgramCodeString = ds.Tables[0].Rows[0]["ProgramCode"] == DBNull.Value ? string.Empty : Convert.ToString(ds.Tables[0].Rows[0]["ProgramCode"]);


                            string jsonString = JsonConvert.SerializeObject(ConnectionString);

                            RedisCacheService radisCacheService = new RedisCacheService(radisCacheServerAddress);
                            radisCacheService.Set("Con" + ProgramCodeString, jsonString);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(isValid);
        }
Exemplo n.º 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);
        }