Ejemplo n.º 1
0
//    byte[] asciiBytes = Encoding.ASCII.GetBytes(value);
    private void _AuthenticateUser(string userName, string password)
    {
        try
        {
            //userName = EncryptionHelper.Encrypt(userName);
            //password = EncryptionHelper.Encrypt(password);
            //  byte[] asciiBytes = Encoding.ASCII.GetBytes(password);
            ////  userName = asciiBytes.ToString();
            //  string encpassword="";
            //  for (int i = 0; i < asciiBytes.Length; i++)
            //  {
            //      int bytevalue = 1000 + asciiBytes[i];
            //      encpassword += Convert.ToString(bytevalue);
            //  }

            //  password = encpassword;
            //Encoding enc = Encoding.GetEncoding(1252);
            // byte[] myByte = new byte[] { 67, 97, 102, 130 }; //Café

            // string str = enc.GetString(asciiBytes);

            // Create the instance
            authenticate = new UserAuthentication();

            // Check the whether user is authenticate.
            authenticate.Authenicate(userName, password);

            mAppManager = authenticate.AppManager;

            Session.Add("TKS_SESSION_ID", Session.SessionID);
            Session.Add("APP_MANAGER", mAppManager);

            HttpRequest request = base.Request;
            string      address = request.UserHostAddress;
            string      browser = request.Browser.Capabilities[""].ToString();

            // user Session insert into DB
            IUserService userService;
            userService            = AppService.Create <IUserService>();
            userService.AppManager = mAppManager;



            userService.InsertSession(Session.SessionID, mAppManager.LoginUser.Id);
            if (userService.InsertUserlog(Session.SessionID, mAppManager.LoginUser.Id, Utility.GetIpAddress(), HttpContext.Current.User.Identity.Name.ToString(), browser, false, CheckValidIP()) != "")
            {
                Session.Clear();
                Session.RemoveAll();
                Session.Abandon();
                Response.Cookies.Clear();
                Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));


                // Remove cache.
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Cache.SetExpires(DateTime.Now.AddDays(-10));
                Response.Redirect("~/Misc/Authorization.aspx");
            }
        }
        catch { throw; }
    }