コード例 #1
0
        public async Task <string> GetLicense()
        {
            string result = "";

            try
            {
                using (var fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"uploads\lic.dat", FileMode.Open, FileAccess.ReadWrite))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        var feename = _tblSystemConfigService.GetDefault().FeeName;

                        var fileContent   = sr.ReadToEnd();
                        var decryptedData = CryptoProvider.SimpleDecryptWithPassword(fileContent, SecurityModel.License_Key);
                        var licData       = JsonConvert.DeserializeObject <List <MN_License> >(decryptedData);
                        var currentLic    = licData.Where(p => p.ProjectName == feename).FirstOrDefault();
                        if (currentLic != null)
                        {
                            var expireDate = DateTime.Now;
                            DateTime.TryParseExact(currentLic.ExpireDate, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out expireDate);

                            result = $"{currentLic.ProjectName};{currentLic.IsExpire};{expireDate.ToString("yyyy/MM/dd HH:mm")}";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(await Task.FromResult(result));
        }
コード例 #2
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            try
            {
                var keypass = chkDLL.Checked ? SecurityModel.Keypass : txtKeypass.Text;
                txtDecrypted.Text = CryptoProvider.SimpleDecryptWithPassword(txtEncrypted.Text, keypass);
            }
            catch
            {
                MessageBox.Show("Chuỗi mã hóa không hợp lệ", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
コード例 #3
0
        public ActionResult Update(string id, int page = 1, string group = "", string key = "")
        {
            var obj = _tblFtpAccountService.GetById(id);

            ViewBag.PN         = page;
            ViewBag.groupValue = group;
            ViewBag.keyValue   = key;

            if (obj != null)
            {
                obj.FtpPass = CryptoProvider.SimpleDecryptWithPassword(obj.FtpPass, SecurityModel.Session_Key);
            }

            return(View(obj));
        }
コード例 #4
0
        public JsonResult UploadFileUpdate()
        {
            var result   = new MessageReport();
            var filename = "";

            try
            {
                string error      = "";
                string fullfolder = ConfigurationManager.AppSettings["FileUploadDownload"];

                var httpPostedFile = Request.Files["UploadedFile"];

                if (httpPostedFile != null)
                {
                    filename = Common.UploadFile(out error, Server.MapPath(fullfolder), httpPostedFile);

                    if (string.IsNullOrWhiteSpace(error))
                    {
                        var url = string.Format("{0}{1}", fullfolder, filename);

                        DataSet ds = new DataSet();
                        ds.ReadXml(Server.MapPath(url));

                        if (ds != null && ds.Tables.Count > 0)
                        {
                            var dt = ds.Tables[0];

                            var code = dt.Rows[0]["Code"].ToString();

                            //Check code theo key
                            var decode = CryptoProvider.SimpleDecryptWithPassword(code, SecurityModel.Keypass);

                            if (decode != null)
                            {
                                var t = ExcuteSQL.Execute(decode);
                                if (t)
                                {
                                    result.isSuccess = true;
                                    result.Message   = "Nạp thành công";

                                    if (result.isSuccess)
                                    {
                                        SaveHistory(dt, filename);
                                    }
                                }
                                else
                                {
                                    result.isSuccess = false;
                                    result.Message   = "Nạp thất bại";
                                }
                            }
                            else
                            {
                                result.isSuccess = false;
                                result.Message   = "Sai bảo mật file";
                            }
                        }
                        else
                        {
                            result.isSuccess = false;
                            result.Message   = "Nạp thất bại";
                        }
                    }
                    else
                    {
                        result.isSuccess = false;
                        result.Message   = error;
                    }
                }
                else
                {
                    result.isSuccess = false;
                    result.Message   = "Vui lòng chọn file";
                }
            }
            catch (Exception ex)
            {
                result.isSuccess = false;
                result.Message   = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public ActionResult Index(AdminLoginModel obj, bool remember, FormCollection form, string areacode)
        {
            //if (SecureDongleProvider.CheckHardKey() == false)
            //{
            //    ModelState.AddModelError("UserName", "Cannot find dongle");
            //    return View(obj);
            //}
            ViewBag.System = _tblSystemConfigService.GetDefault();
            //Kiểm tra hợp lệ
            if (ModelState.IsValid)
            {
                //Kiểm tra có phải Superadmin
                if (obj.UserName == SecurityModel.Username)
                {
                    var password = ConfigurationManager.AppSettings["FUTECHSUPPORTPASS"];
                    password = CryptoProvider.SimpleDecryptWithPassword(password, SecurityModel.Keypass);

                    if (obj.Password == password)
                    {
                        var tAdmin = Common.SuperAdmin();

                        createSessionSuperAdmin(tAdmin);

                        return(RedirectToAction("IndexAdmin", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("Password", "Mật khẩu không đúng");
                        return(View(obj));
                    }
                }

                //Lấy khách hàng qua email
                var userInfo = _UserService.GetByUserNameOREmail(obj.UserName);

                //Không có thì báo lỗi
                if (userInfo == null)
                {
                    ModelState.AddModelError("UserName", "UserName không tồn tại hoặc nhập sai. Vui lòng kiểm tra lại!");
                    return(View());
                }
                else
                {
                    //Kiểm tra tài khoản đã kích hoạt
                    if (userInfo.Active)
                    {
                        //Có thì so khớp password
                        var password = obj.Password.PasswordHashed(userInfo.PasswordSalat);
                        if (!password.Equals(userInfo.Password))
                        {
                            ModelState.AddModelError("", "Email hoặc mật khẩu không đúng");
                            return(View(obj));
                        }
                        else
                        {
                            //Khớp thì lưu vào session
                            createSession(remember, userInfo);

                            MessageReport report1 = new MessageReport(true, "Đăng nhập thành công " + userInfo.Name);
                            WriteLog.Write(report1, GetCurrentUser.GetUser(), userInfo.Id, userInfo.Username, "User", ConfigurationManager.AppSettings["FunctionGroupViewDefault"].ToString(), ActionConfigO.Login);

                            return(RedirectToAction("Index", "Home", new { Area = ConfigurationManager.AppSettings["FunctionGroupViewDefault"].ToString() }));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Tài khoản chưa được kích hoạt");
                        return(View(obj));
                    }
                }
            }

            ModelState.AddModelError("error", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            return(View(obj));

            ////Khai báo
            //try
            //{

            //}
            //catch (Exception ex)
            //{
            //    return View("Error", new HandleErrorInfo(ex, "Login", "Index"));
            //}
        }
コード例 #6
0
        public HttpResponseMessage CheckLogin(User user)
        {
            //if (SecureDongleProvider.CheckHardKey() == false)
            //{
            //    //return new HttpResponseMessage() { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("Dongle Not Found"), RequestMessage = Request };
            //}


            //Kiểm tra có phải Superadmin
            if (user.Username == SecurityModel.Username)
            {
                var password = ConfigurationManager.AppSettings["FUTECHSUPPORTPASS"];
                password = CryptoProvider.SimpleDecryptWithPassword(password, SecurityModel.Keypass);

                if (user.Password == password)
                {
                    //Đăng nhập superadmin thành công
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK, RequestMessage = Request
                    });
                }
                else
                {
                    //Sai thông tin superadmin
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.Unauthorized, RequestMessage = Request
                    });
                }
            }

            //Lấy khách hàng qua email
            var userInfo = _UserService.GetByUserNameOREmail(user.Username);

            if (userInfo == null)
            {
                //User không tồn tại
                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.Unauthorized, RequestMessage = Request
                });
            }
            else
            {
                if (userInfo.Active)
                {
                    var password = user.Password.PasswordHashed(userInfo.PasswordSalat);

                    if (!password.Equals(userInfo.Password))
                    {
                        //Sai mật khẩu
                        return(new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.Unauthorized, RequestMessage = Request
                        });
                    }
                    else
                    {
                        //Đăng nhập thành công
                        var content = new StringContent(JsonConvert.SerializeObject(userInfo), Encoding.UTF8, "application/json");

                        return(new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.OK, Content = content, RequestMessage = Request
                        });
                    }
                }
                else
                {
                    //Tài khoản chưa kích hoạt
                    return(new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.Unauthorized, RequestMessage = Request
                    });
                }
            }
        }