/// <summary> /// 生成包含用户角色的验证票据 (加密处理) /// </summary> /// <param name="key">用户ID</param> /// <param name="userRole">用户角色</param> /// <returns></returns> private string CreateTicket( string key, UserLoginRole userRole) { var ticket = key + "|" + userRole; var encryptTicket = CryptTools.Encrypt(ticket, Secret); return(encryptTicket); }
public void GenernateRegister() { var licenseFilePath = Path.Combine(AppContext.BaseDirectory, @"Register"); var productInfo = new ProductInfo() { MainBoardSerialNumber = this.GetBIOSSerialNumber() }; File.WriteAllText(licenseFilePath, CryptTools.Encrypt(JsonHelper.SerializeObject(productInfo), LicenseManager.SecretRegister)); }
//终端客户端使用 public ClientMessageInspector(string userName, string password) { //在客户端发送前添加认证信息 userName = CryptTools.Encrypt(userName, CryptConstants.PassKey); password = CryptTools.Encrypt(password, CryptConstants.PassKey); this.HeadToServer.Clear(); this.HeadToServer.Add("UserName", userName); this.HeadToServer.Add("Password", password); }
public void GenernateRegister() { var licenseFilePath = Path.Combine(AppContext.BaseDirectory, @"Register"); var productInfo = new ProductInfo() { MainBoardSerialNumber = this.GetBIOSSerialNumber() }; if (string.IsNullOrWhiteSpace(productInfo.MainBoardSerialNumber)) { throw new Exception("Open application with administrators"); } File.WriteAllText(licenseFilePath, CryptTools.Encrypt(JsonConvert.SerializeObject(productInfo), "BlocksRegister")); }
public int Handle(CreateUserCommand command) { var admin = (from a in _userRepository.FindAll() where a.UserName == command.UserName || a.RealName == command.RealName select a).SingleOrDefault(); if (admin != null) { throw new BusinessException("创建用户失败:已存在相同的用户帐号/用户昵称"); } if (string.IsNullOrEmpty(command.Domain)) { command.Domain = command.UserName; } var user = _userRepository.Save(new User() { Card = command.Card, CreateDate = DateTime.Now, Domain = command.Domain, Email = command.Email, EmailValidate = command.EmailValidate, ImgHead = command.ImgHead, LastLoginDate = null, LastLoginIp = "", LastDateTime = DateTime.Now, LoginDate = null, LoginIp = "", Paw = CryptTools.Md5(command.Paw), DesPassword = CryptTools.Encrypt(command.Paw, CacheKeys.ECLOGIN_PASSWORD_SECRET), Phone = command.Phone, QQ = command.QQ, RealName = command.RealName, SmallImgHead = command.SmallImgHead, StandardImgHead = command.StandardImgHead, UserName = command.UserName, UserSex = command.UserSex, UserState = command.UserState, BlogName = command.BlogName, BlogDesc = command.BlogDesc, EnRealName = command.EnRealName, UserRole = UserRole.User }); return(user.Id); }
public void GenernateLicenseWithRegister() { var registerFilePath = Path.Combine(AppContext.BaseDirectory, @"Register"); if (!File.Exists(registerFilePath)) { throw new LicenseException(StringLocal.Format("Register file not found.")); } ProductInfo productInfo; try { var fileInfo = File.ReadAllText(registerFilePath); productInfo = JsonHelper.DeserializeObject <ProductInfo>(CryptTools.Decrypt(fileInfo, LicenseManager.SecretRegister)); } catch (Exception) { throw new LicenseException(StringLocal.Format("License file not found or no license.")); } CryptTools.Encrypt(JsonHelper.SerializeObject(productInfo), LicenseManager.SecretRegister); var licenseFilePath = Path.Combine(AppContext.BaseDirectory, @"License"); File.WriteAllText(licenseFilePath, CryptTools.Encrypt(JsonHelper.SerializeObject(productInfo), LicenseManager.Secret)); }
public ActionResult CheckUserLogin(string userAccount, string userPwd) { IDictionary <string, string> ls = new Dictionary <string, string>(); var user = new User_Profile_Model { User_Account = userAccount, User_Pwd = userPwd }; ls.Add("User_Account", user.User_Account); ls.Add("Logging_IP", HttpContext.Request.ServerVariables["REMOTE_ADDR"]); ls.Add("Machine_Name", HttpContext.Request.UserHostName); ls.Add("Logging_Date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); try { //NBCMSLoggerManager.Error( "123".GetPWDMD5()); var userInfoSvr = new UserInfoServices(); var userInfo = userInfoSvr.checkUserLogin(user); string remarkMsg; if (userInfo != null) { if (userInfo.UserStatusID != 1) { remarkMsg = "User does not allow to login CMS system"; ls.Add("Display_Name", user.Display_Name); ls.Add("LoggingStatue", "1"); ls.Add("Remark", remarkMsg); NBCMSLoggerManager.NBCMSLogger("Login", "", ls); return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = remarkMsg })); } //setting cookies var serializer = new JavaScriptSerializer(); //String userInfoCookies = serializer.Serialize(new //{ // User_Guid = userInfo.User_Guid, // User_Account = userInfo.User_Account, // Display_Name = userInfo.Display_Name, // User_Pwd = userInfo.User_Pwd, // IsChannelControl = userInfo.IsChannelControl//add by Lee 2013-11-4 //}); var userInfoCookies = serializer.Serialize(new { userInfo.User_Guid, userInfo.User_Account, userInfo.Display_Name, userInfo.User_Pwd, userInfo.IsChannelControl//add by Lee 2013-11-4 }); //userInfoSvr.UpdateUserStats("1", userInfo.User_Account); //Add by Lee 2013年12月2日10:49:38 just for testing //FormsAuthentication.SetAuthCookie(userInfo.User_Account, false); var keys = ConfigurationManager.AppSettings["userInfoCookiesKey"]; var cookie = new HttpCookie(keys, CryptTools.Encrypt(userInfoCookies)); //不设置Cookies过期时间,让Cookies伴随浏览器关闭就自动结束 //DateTime dt = DateTime.Now; //TimeSpan ts = new TimeSpan(0, 0, 0, secExpires, 0);//过期时间为??秒钟 //cookie.Expires = dt.Add(ts);//设置过期时间 Response.AppendCookie(cookie); //Session["UserInfo"] = userInfo; //新增功能:记录用户最后一次登录的时间 ls.Add("Display_Name", userInfo.Display_Name); ls.Add("LoggingStatue", "0"); NBCMSLoggerManager.NBCMSLogger("Login", "", ls); userInfoSvr.UpdateUserLast_Logon(userInfo.User_Guid); return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = userInfo })); } remarkMsg = "User does not exist or password is wrong"; ls.Add("Display_Name", user.Display_Name); ls.Add("LoggingStatue", "1"); ls.Add("Remark", remarkMsg); NBCMSLoggerManager.NBCMSLogger("Login", "", ls); return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = remarkMsg })); } catch (Exception ex) { NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(""); return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = ex.Message })); } }