public override bool Insert(UserInfo obj, DbTransaction trans = null) { UserInfo info = (UserInfo)obj; info.Password = EncodeHelper.DesEncrypt(Const.defaultPwd); return(base.Insert(obj, trans)); }
private void btn_login_Click(object sender, EventArgs e) { userName = textBox_UserName.Text.Trim(); password = textBox_Password.Text.Trim(); if (ValidationService.CheckNull(userName) || ValidationService.CheckNull(password)) { XtraMessageBox.Show("用户名或密码不能为空!"); return; } //CheckAdminUser(); UserInfo userInfo = new UserInfo(); userInfo.UserName = userName; userInfo.Password = EncodeHelper.DesEncrypt(password); if (userName == "admin" && password == "admin") //if (MongoHelper.GetInstance().CheckUserLogin(userInfo)) { this.Hide(); FrmStartup spScreen = new FrmStartup(); Program.SetMainForm(spScreen); Program.ShowMainForm(); //Thread.Sleep(5000); //Program.SetMainForm(new FrmMain()); //Program.ShowMainForm(); if (checkBoxRemember.Checked == true) { string string64 = EncodeHelper.DesEncrypt(userName + "|" + password); parsedData["GeneralConfiguration"]["LoginInfo"] = string64; fileIniData.WriteFile(iniFilePath, parsedData); } else { parsedData["GeneralConfiguration"]["LoginInfo"] = ""; fileIniData.WriteFile(iniFilePath, parsedData); } if (radioGroup1.SelectedIndex == 0) { parsedData["GeneralConfiguration"]["Index"] = "0"; fileIniData.WriteFile(iniFilePath, parsedData); } else if (radioGroup1.SelectedIndex == 1) { parsedData["GeneralConfiguration"]["Index"] = "1"; fileIniData.WriteFile(iniFilePath, parsedData); } else if (radioGroup1.SelectedIndex == 2) { parsedData["GeneralConfiguration"]["Index"] = "2"; fileIniData.WriteFile(iniFilePath, parsedData); } this.Close(); } else { XtraMessageBox.Show("用户名或密码错误!"); return; } }
private void simpleButtonConform_Click(object sender, EventArgs e) { userName = textBox_UserName.Text.Trim(); password = textBox_Password.Text.Trim(); if (ValidationService.CheckNull(userName) || ValidationService.CheckNull(password)) { XtraMessageBox.Show("用户名或密码不能为空!"); return; } if (null != mUserInfo) { MongoHelper.GetInstance().DeleteUserInfo(mUserInfo); } UserInfo userInfo = new UserInfo(); userInfo.UserName = userName; userInfo.Password = EncodeHelper.DesEncrypt(password); userInfo.CreateTime = new BsonDateTime(DateTime.Now); userInfo.AccountName = textBox_AccountName.Text; userInfo.PhoneNumber = textBox_Phone.Text; userInfo.EmailAddress = textBox_Email.Text; userInfo.UserRole = "1"; bool ret = MongoHelper.GetInstance().AddUser(userInfo); if (ret) { if (bModified) { XtraMessageBox.Show("修改成功!"); } else { XtraMessageBox.Show("添加成功!"); } } else { if (bModified) { XtraMessageBox.Show("修改失败!"); } else { XtraMessageBox.Show("添加失败!"); } return; } this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); }
private bool CheckAdminUser() { //默认创建admin用户 UserInfo userInfo = new UserInfo(); userInfo.CreateTime = new BsonDateTime(DateTime.Now); userInfo.UserName = "******"; userInfo.Password = EncodeHelper.DesEncrypt("admin"); userInfo.AccountName = "管理员"; userInfo.UserRole = "0"; userInfo.EmailAddress = "*****@*****.**"; userInfo.PhoneNumber = "1356897895"; if (!MongoHelper.GetInstance().CheckUserInfo(userInfo)) { MongoHelper.GetInstance().AddUser(userInfo); } return(true); }
/// <summary> /// 修改用户密码 /// </summary> /// <param name="userName">修改用户名</param> /// <param name="userPassword">用户密码(未加密)</param> /// <param name="systemType">系统类型</param> /// <param name="ip">IP地址</param> /// <param name="macAddr">Mac地址</param> /// <returns></returns> public bool ModifyPassword(string userName, string userPassword, string systemType, string ip, string macAddr) { bool result = false; UserInfo userByName = this.GetUserByName(userName); if (userByName != null) { userPassword = EncodeHelper.DesEncrypt(userPassword); userByName.Password = userPassword; result = userDal.Update(userByName, userByName.ID.ToString()); if (result) { //记录用户修改密码日志 BLLFactory <LoginLog> .Instance.AddLoginLog(userByName, systemType, ip, macAddr, "用户修改密码"); } } return(result); }
/// <summary> /// 管理员重置密码 /// </summary> /// <param name="loginUser_ID">登陆账号ID</param> /// <param name="changeUser_ID">修改账号ID</param> /// <param name="ip">登陆IP</param> /// <param name="macAddr">登陆Mac地址</param> /// <returns></returns> public bool ResetPassword(int loginUser_ID, int changeUser_ID, string systemType, string ip, string macAddr) { bool result = false; UserInfo loginInfo = this.FindByID(loginUser_ID); UserInfo changeInfo = this.FindByID(changeUser_ID); if (loginInfo != null && changeInfo != null) { //string initPassword = EncryptHelper.ComputeHash("12345678", changeInfo.Name.ToLower()); string initPassword = EncodeHelper.DesEncrypt(Const.defaultPwd); changeInfo.Password = initPassword; result = userDal.Update(changeInfo, changeInfo.ID); if (result) { //记录用户修改密码日志 string message = string.Format("{0}重置了用户【{1}】的登陆密码", loginInfo.FullName, changeInfo.FullName); BLLFactory <LoginLog> .Instance.AddLoginLog(loginInfo, systemType, ip, macAddr, message); } } return(result); }
/// <summary> /// 根据用户名、密码验证用户身份有效性 /// </summary> /// <param name="userName">用户名称</param> /// <param name="userPassword">用户密码</param> /// <param name="systemtypeId">系统类型ID</param> /// <returns></returns> public string VerifyUser(string userName, string userPassword, string systemtypeId, string ip, string mac) { if (string.IsNullOrEmpty(systemtypeId)) { return(""); } string identity = ""; UserInfo userInfo = this.GetUserByName(userName); if (userInfo != null && userInfo.IsExpire == (Int16)IsExpire.否 && userInfo.IsDelete == (Int16)IsDelete.否) { bool ipAccess = BLLFactory <BlackIP> .Instance.ValidateIPAccess(ip, userInfo.Id); if (ipAccess) { //userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); Console.WriteLine(string.Format("DEBUG: 用户名:{0}, 明文密码:{1}, 密文密码:{2}, 数据库密码:{3}", userInfo.Name, userPassword, EncodeHelper.DesEncrypt(userPassword), userInfo.Password)); userPassword = EncodeHelper.DesEncrypt(userPassword); if (userPassword == userInfo.Password) { //更新用户的登录时间和IP地址 dal.UpdateUserLoginData(userInfo.Id, ip, mac); //identity = EncryptHelper.EncryptStr(userName + Convert.ToString(Convert.ToChar(1)) + userPassword, systemType); identity = EncodeHelper.DesEncrypt(userName + Convert.ToString(Convert.ToChar(1)) + userPassword); //记录用户登录日志 BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemtypeId, ip, mac, "用户登录"); } } else { BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemtypeId, ip, mac, "用户登录操作被黑白名单禁止登陆!"); } } return(identity); }
/// <summary> /// 判断用户是否为超级管理员 (作废) /// </summary> /// <param name="userName">用户名称</param> /// <returns></returns> //public bool UserIsSuperAdmin(string userName) //{ // return UserInRole(userName, RoleInfo.SuperAdminName); //} /// <summary> /// 判断用户是否为管理员,超级管理员、公司级别的系统管理员均通过。(作废) /// </summary> /// <param name="userName">用户名称</param> /// <returns></returns> //public bool UserIsAdmin(string userName) //{ // bool result = UserInRole(userName, RoleInfo.SuperAdminName); // if (!result) // { // result = UserInRole(userName, RoleInfo.CompanyAdminName); // } // return result; //} /// <summary> /// 根据用户名、密码验证用户身份有效性 /// </summary> /// <param name="userName">用户名称</param> /// <param name="userPassword">用户密码</param> /// <param name="systemType">系统类型ID</param> /// <param name="ip">IP地址</param> /// <param name="macAddr">Mac网卡地址</param> /// <returns></returns> public string VerifyUser(string userName, string userPassword, string systemType, string ip, string macAddr) { if (string.IsNullOrEmpty(systemType)) { return(""); } string identity = ""; UserInfo userInfo = this.GetUserByName(userName); if (userInfo != null && !userInfo.IsExpire && !userInfo.Deleted) { bool ipAccess = BLLFactory <BlackIP> .Instance.ValidateIPAccess(ip, userInfo.ID); if (ipAccess) { //userPassword = EncryptHelper.ComputeHash(userPassword, userName.ToLower()); userPassword = EncodeHelper.DesEncrypt(userPassword); if (userPassword == userInfo.Password) { //更新用户的登录时间和IP地址 this.userDal.UpdateUserLoginData(userInfo.ID, ip, macAddr); //identity = EncryptHelper.EncryptStr(userName + Convert.ToString(Convert.ToChar(1)) + userPassword, systemType); identity = EncodeHelper.DesEncrypt(userName + Convert.ToString(Convert.ToChar(1)) + userPassword); //记录用户登录日志 BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemType, ip, macAddr, "用户登录"); } } else { BLLFactory <LoginLog> .Instance.AddLoginLog(userInfo, systemType, ip, macAddr, "用户登录操作被黑白名单禁止登陆!"); } } return(identity); }
public static string EncryptStr(string source, string key) { key = key.PadLeft(8, 'x'); return(EncodeHelper.DesEncrypt(source, key)); }
/// <summary> /// 加密并保存当前时间到"独立存贮空间" (以分号(;)追加保存) /// </summary> public static void SaveDataTime(DateTime fromDate) { string fromDataTime = fromDate.ToString("MM-dd-yyyy HH:mm:ss"); string oldTime = GetDataTime().Trim(); if (!string.IsNullOrEmpty(oldTime)) { fromDataTime = oldTime + ";" + fromDataTime; //追加最后时间到左边 } fromDataTime = EncodeHelper.DesEncrypt(fromDataTime, UIConstants.IsolatedStorageEncryptKey); //加密 #region 将fromDataTime保存在"独立存贮空间" string username = fromDataTime; //按用户、域、程序集获取独立存储区 IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore( IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null); string[] myusername = isoStore.GetDirectoryNames(UIConstants.IsolatedStorageDirectoryName); IsolatedStorageFileStream isoStream1 = null; if (myusername.Length == 0) //没有目录 { //创建目录 isoStore.CreateDirectory(UIConstants.IsolatedStorageDirectoryName); //创建文件 using (isoStream1 = new IsolatedStorageFileStream(UIConstants.IsolatedStorage, FileMode.Create, isoStore)) { //写入文件 using (StreamWriter writer = new StreamWriter(isoStream1)) { writer.WriteLine(fromDataTime); } } } else { myusername = isoStore.GetFileNames(UIConstants.IsolatedStorage); if (myusername.Length == 0) //没有文件 { //创建文件 using (isoStream1 = new IsolatedStorageFileStream(UIConstants.IsolatedStorage, FileMode.Create, isoStore)) { //写入文件 using (StreamWriter writer = new StreamWriter(isoStream1)) { writer.WriteLine(fromDataTime); } } } else { using (isoStream1 = new IsolatedStorageFileStream(UIConstants.IsolatedStorage, FileMode.Open, isoStore)) { //写入文件 using (StreamWriter writer = new StreamWriter(isoStream1)) { writer.WriteLine(fromDataTime); } } } } #endregion }
private void btnEncrypt_Click(object sender, EventArgs e) { string original = "测试加密字符串"; Console.WriteLine("original:" + original); string encrypt = EncodeHelper.SHA256(original); Console.WriteLine("EncodeHelper.SHA256:" + encrypt); //DES加解密 encrypt = EncodeHelper.DesEncrypt(original); Console.WriteLine("EncodeHelper.DesEncrypt:" + encrypt); string decrypt = EncodeHelper.DesDecrypt(encrypt); Console.WriteLine("EncodeHelper.DesDecrypt:" + decrypt); //MD5加密 encrypt = EncodeHelper.MD5Encrypt(original); Console.WriteLine("EncodeHelper.MD5Encrypt:" + encrypt); encrypt = EncodeHelper.MD5EncryptHash(original); Console.WriteLine("EncodeHelper.MD5EncryptHash:" + encrypt); encrypt = EncodeHelper.MD5EncryptHashHex(original); Console.WriteLine("EncodeHelper.MD5EncryptHashHex:" + encrypt); encrypt = EncodeHelper.EncyptMD5_3_16(original); Console.WriteLine("EncodeHelper.EncyptMD5_3_16:" + encrypt); //Base64加解密 encrypt = EncodeHelper.Base64Encrypt(original); Console.WriteLine("EncodeHelper.Base64Encrypt:" + encrypt); decrypt = EncodeHelper.Base64Decrypt(encrypt); Console.WriteLine("EncodeHelper.Base64Encrypt:" + decrypt); encrypt = EncodeHelper.AES_Encrypt(original); Console.WriteLine("EncodeHelper.AES_Encrypt:" + encrypt); decrypt = EncodeHelper.AES_Decrypt(encrypt); Console.WriteLine("EncodeHelper.AES_Decrypt:" + decrypt); //MD5加密字符串然后检查是否被篡改 encrypt = MD5Util.GetMD5_32(original); bool flag = MD5Util.ValidateValue(encrypt); Console.WriteLine("flag: " + flag); //为文件增加MD5编码标签,然后验证是否被修改 string file = @"DB\test1.xls"; bool flag2 = MD5Util.AddMD5(file); Console.WriteLine("flag2: " + flag2); //对给定路径的文件进行验证,如果一致返回True,否则返回False bool flag3 = MD5Util.CheckMD5(file); Console.WriteLine("flag3: " + flag3); //生成加解密私钥、公钥 string publicKey = ""; string privateKey = ""; RSASecurityHelper.GenerateRSAKey(out privateKey, out publicKey); string originalString = "testdata"; string encryptedString = RSASecurityHelper.RSAEncrypt(publicKey, originalString); string originalString2 = RSASecurityHelper.RSADecrypt(privateKey, encryptedString); if (originalString == originalString2) { MessageDxUtil.ShowTips("解密完全正确"); } else { MessageDxUtil.ShowWarning("解密失败"); } string regcode = RSASecurityHelper.RSAEncrypSignature(privateKey, originalString); bool validated = RSASecurityHelper.Validate(originalString, regcode, publicKey); MessageDxUtil.ShowTips(validated ? "验证成功" : "验证失败"); }