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
        public ResponseModel authenticateUser()
        {
            string X_Authorized_Programcode = Convert.ToString(Request.Headers["X-Authorized-Programcode"]);
            string X_Authorized_userId      = Convert.ToString(Request.Headers["X-Authorized-userId"]);
            string X_Authorized_password    = Convert.ToString(Request.Headers["X-Authorized-password"]);
            string X_Authorized_Domainname  = Convert.ToString(Request.Headers["X-Authorized-Domainname"]);

            ResponseModel resp = new ResponseModel();

            try
            {
                securityCaller newSecurityCaller = new securityCaller();
                AccountModal   account           = new AccountModal();
                string         programCode       = X_Authorized_Programcode.Replace(' ', '+');
                string         domainName        = X_Authorized_Domainname.Replace(' ', '+');
                string         userId            = X_Authorized_userId.Replace(' ', '+');
                string         password          = X_Authorized_password.Replace(' ', '+');

                if (!string.IsNullOrEmpty(programCode) && !string.IsNullOrEmpty(domainName) && !string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(password))
                {
                    account = newSecurityCaller.validateUser(new SecurityService(Cache, Db), programCode, domainName, userId, password);

                    if (!string.IsNullOrEmpty(account.Token))
                    {
                        account.IsActive  = true;
                        resp.Status       = true;
                        resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        resp.ResponseData = account;
                        resp.Message      = "Valid Login";
                    }
                    else
                    {
                        account.IsActive  = false;
                        resp.Status       = true;
                        resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        resp.ResponseData = account;
                        resp.Message      = "In-Valid Login";
                    }
                }
                else
                {
                    resp.Status       = false;
                    resp.ResponseData = account;
                    resp.Message      = "Invalid Login";
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(resp);
        }
Exemplo n.º 3
0
 public override void OnAuthorization(AuthorizationContext filterContext)
 {
     if (string.IsNullOrEmpty(SessionPersister.Username))
     {
         filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "AccessDenied", action = "Index" }));
     }
     else
     {
         AccountModal    accountModel    = new AccountModal();
         CustomPrincipal customPrincipal = new CustomPrincipal(accountModel.find(SessionPersister.Username));
         if (!customPrincipal.IsInRole(Roles))
         {
             filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "AccessDenied", action = "Index" }));
         }
     }
 }
Exemplo n.º 4
0
        public ResponseModel AuthenticateUser()
        {
            string X_Authorized_Programcode = Convert.ToString(Request.Headers["X-Authorized-Programcode"]);
            string X_Authorized_userId      = Convert.ToString(Request.Headers["X-Authorized-userId"]);
            string X_Authorized_password    = Convert.ToString(Request.Headers["X-Authorized-password"]);
            string X_Authorized_Domainname  = Convert.ToString(Request.Headers["X-Authorized-Domainname"]);

            ResponseModel resp = new ResponseModel();

            try
            {
                securityCaller newSecurityCaller = new securityCaller();
                AccountModal   account           = new AccountModal();
                string         Programcode       = X_Authorized_Programcode.Replace(' ', '+');
                string         Domainname        = X_Authorized_Domainname.Replace(' ', '+');
                string         userId            = X_Authorized_userId.Replace(' ', '+');
                string         password          = X_Authorized_password.Replace(' ', '+');


                string _data = "";
                if (X_Authorized_Programcode != null)
                {
                    X_Authorized_Programcode = SecurityService.DecryptStringAES(X_Authorized_Programcode);

                    RedisCacheService cacheService = new RedisCacheService(_radisCacheServerAddress);
                    if (cacheService.Exists("Con" + X_Authorized_Programcode))
                    {
                        _data = cacheService.Get("Con" + X_Authorized_Programcode);
                        _data = JsonConvert.DeserializeObject <string>(_data);
                    }
                }

                if (!string.IsNullOrEmpty(Programcode) && !string.IsNullOrEmpty(Domainname) && !string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(password))
                {
                    account = newSecurityCaller.validateUser(new SecurityService(_data, _radisCacheServerAddress), Programcode, Domainname, userId, password);

                    if (!string.IsNullOrEmpty(account.Token))
                    {
                        account.IsActive  = true;
                        resp.Status       = true;
                        resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        resp.ResponseData = account;
                        resp.Message      = "Valid Login";
                    }
                    else
                    {
                        account.IsActive  = false;
                        resp.Status       = true;
                        resp.StatusCode   = (int)EnumMaster.StatusCode.Success;
                        resp.ResponseData = account;
                        resp.Message      = "In-Valid Login";
                    }
                }
                else
                {
                    resp.Status       = false;
                    resp.ResponseData = account;
                    resp.Message      = "Invalid Login";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(resp);
        }