Пример #1
0
 public override void OnAuthorization(HttpActionContext actionContext)
 {
     if (actionContext.Request.Headers.Authorization is null)
     {
         actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, new Exception("Bạn không có quyền truy cập tính năng  này"));
     }
     else
     {
         try
         {
             string   authenticationToken       = actionContext.Request.Headers.Authorization.Parameter;
             string   decodeAuthenticationToken = Encode.Decrypt(authenticationToken);
             string[] account  = decodeAuthenticationToken.Split(':');
             string   userName = account[0];
             string   password = Encode.MD5(account[0]);
             using (var db = new DB())
             {
                 if (db.TaiKhoans.FirstOrDefault(x => x.tentaikhoan == userName && x.matkhau == password) == null)
                 {
                     Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(userName), null);
                 }
                 else
                 {
                     actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, new Exception("Bạn không có quyền truy cập tính năng  này"));
                 }
             }
         }
         catch (Exception ex)
         {
             actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("Bạn không có quyền truy cập tính năng  này"));
         }
     }
 }
Пример #2
0
 public bool TryGetRole()
 {
     try
     {
         string token           = Request.Cookies["token"].Value;
         string danhsachmanhinh = Request.Cookies["danhsachmanhinh"].Value;
         string setingstyle     = Request.Cookies["setingstyle"].Value;
         string avatar          = Request.Cookies["avatar"].Value;
         string hoten           = Request.Cookies["hoten"].Value;
         if (token is null || danhsachmanhinh is null)
         {
             return(false);
         }
         Session["userName"]     = Encode.Decrypt(token).Split(':')[0];
         Session["setingstyle"]  = setingstyle;
         Session["avatar"]       = avatar;
         Session["hoten"]        = hoten;
         Session["acceptScreen"] = JsonConvert.DeserializeObject <List <string> >(Encode.Decrypt(danhsachmanhinh));
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Пример #3
0
        private string GetCurrentUser(string authenticationToken, out List <string> acceptScreen)
        {
            authenticationToken = System.Web.HttpUtility.UrlDecode(authenticationToken);
            string decodeAuthenticationToken = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationToken));

            decodeAuthenticationToken = Encode.Decrypt(decodeAuthenticationToken);
            string[] account = decodeAuthenticationToken.Split(':');
            acceptScreen = JsonConvert.DeserializeObject <List <string> >(account[2]);
            return(account[0]);
        }
        private void frm_Login_Load(object sender, EventArgs e)
        {
            frm_StartForm f = new frm_StartForm();

            f.ShowDialog();
            string line = "";

            using (StreamReader sr = new StreamReader("Config.ini"))
            {
                if ((line = sr.ReadLine()) != null)
                {
                    string[] temp = line.Split(';');
                    this.textBox_UserName.Text = Encode.Decrypt(temp[0]).Trim();
                    this.textBox_PassWord.Text = Encode.Decrypt(temp[1]).Trim();
                }
            }
        }