private void validaAcesso() { string cripSenha = ""; SymmCrypto crip = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); cripSenha = crip.Encrypting(txtSenha.Text.Trim(), "6666"); if (txtLogin.Text.Trim() != "ADMCARGA") { try //Para acesso ao banco. { tbl_userTableAdapter.buscaUsuario(pORTARIADataSet.tbl_user, txtLogin.Text); if (pORTARIADataSet.tbl_user.Rows.Count > 0) { if (pORTARIADataSet.tbl_user[0].senha.Trim() != cripSenha) { MessageBox.Show("Usuário ou senha inválido.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSenha.Text = ""; return; } } else { MessageBox.Show("Usuário não localizado", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (System.Data.SqlClient.SqlException err) { MessageBox.Show(err.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception err) { MessageBox.Show(err.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Program.strUsuarioAtu = txtLogin.Text; Program.flgAcesso = true; this.Close(); } else { if (txtSenha.Text.Trim() == "CARGA") { Program.strUsuarioAtu = txtLogin.Text; Program.flgAcesso = true; this.Close(); } else { MessageBox.Show("Usuário ou senha inválido.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtLogin.Focus(); } } }
public override string HashPassword(string password) { if (password == null) { throw new ArgumentNullException("Password is Null"); } SymmCrypto symm = new SymmCrypto(_Key, _IV); return(Convert.ToBase64String(symm.EncryptFromString(password))); }
public byte[] HashPass(string password) { if (password == null) { throw new ArgumentNullException("Password is Null"); } SymmCrypto symm = new SymmCrypto(_Key, _IV); return(symm.EncryptFromString(password)); }
public AfterCaseController() { _auditDal = new BaseAuditDAL(); _salesGroupDal = new SalesGroupDAL(); _relationPersonAuditDal = new RelationPersonAuditDAL(); _lendingDal = new LendingDAL(); _mortgageBll = new MortgageBll(); _dictionaryBll = new DictionaryBLL(); symm = new SymmCrypto(_Key, _IV); }
public static string FromHatsString(this string encryptValue) { if (string.IsNullOrEmpty(encryptValue) || string.IsNullOrWhiteSpace(encryptValue)) { throw new ArgumentNullException("encryptValue", "参数不能为空"); } byte[] valBytes = Convert.FromBase64String(encryptValue); byte[] keyBytes = Encoding.UTF8.GetBytes(Key); byte[] ivBytes = Encoding.UTF8.GetBytes(Iv); string decryptedStr = new SymmCrypto(keyBytes, ivBytes).DecryptToString(valBytes, Encoding.UTF8); return(decryptedStr); }
public static Des FromHatsString <Des>(this string encryptValue) where Des : new() { if (string.IsNullOrEmpty(encryptValue) || string.IsNullOrWhiteSpace(encryptValue)) { throw new ArgumentNullException("encryptValue", "参数不能为空"); } byte[] valBytes = Convert.FromBase64String(encryptValue); byte[] keyBytes = Encoding.UTF8.GetBytes(Key); byte[] ivBytes = Encoding.UTF8.GetBytes(Iv); string decryptedBytes = new SymmCrypto(keyBytes, ivBytes).DecryptToString(valBytes, Encoding.UTF8); return(JsonConvert.DeserializeObject <Des>(decryptedBytes)); }
public static string ToHatsString(this string srcVal) { if (srcVal == null) { throw new ArgumentNullException("srcVal", "参数不能为空"); } byte[] valBytes = Encoding.UTF8.GetBytes(srcVal); byte[] keyBytes = Encoding.UTF8.GetBytes(Key); byte[] ivBytes = Encoding.UTF8.GetBytes(Iv); byte[] encrypted = new SymmCrypto(keyBytes, ivBytes).Encrypt(valBytes); return(Convert.ToBase64String(encrypted)); }
private bool Dueno() { // TIT Oct 2018, ahora lo dejamos libre bool puede = true; // SecuritySystem.CurrentUserName == "root"; Empresa emp = View.ObjectSpace.FindObject <Empresa>(null); const string contra = "mdBc591/Q7UJwKzkmTEQ8w=="; string rfc = emp != null ? emp.Compania.Rfc : "AAA010101AAA"; string rfcaux = new SymmCrypto(SymmCrypto.SymmProvEnum.DES). Decrypting((emp == null || string.IsNullOrEmpty(emp.Contra)) ? contra /*"LICENCIA"*/ : emp.Contra, yek); string[] toks = rfcaux.Split('|'); return(puede || (toks[0] == rfc)); }
public static string ToHatsString <Src>(this Src srcVal) { if (srcVal == null) { throw new ArgumentNullException("srcVal", "参数不能为空"); } string serializedValue = JsonConvert.SerializeObject(srcVal); byte[] valBytes = Encoding.UTF8.GetBytes(serializedValue); byte[] keyBytes = Encoding.UTF8.GetBytes(Key); byte[] ivBytes = Encoding.UTF8.GetBytes(Iv); byte[] encrypted = new SymmCrypto(keyBytes, ivBytes).Encrypt(valBytes); return(Convert.ToBase64String(encrypted)); }
private void btnAlterar_Click(object sender, EventArgs e) { if (validaControle()) { try { string cripSenha = ""; SymmCrypto crip = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); cripSenha = crip.Encrypting(txtNovaSenha.Text.Trim(), "6666"); tbl_userTableAdapter.atualizaSenha(cripSenha, lblViewUsr.Text); MessageBox.Show("Senha alterada com sucesso!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception err) { MessageBox.Show(err.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void salvar() { string cripSenha; SymmCrypto crip = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); cripSenha = crip.Encrypting("autoneum", "6666"); try { pORTARIADataSet.tbl_user.Clear(); tbl_userTableAdapter.buscaUsuario(pORTARIADataSet.tbl_user, txtUsuario.Text.Trim()); //busca usuario na tabela. if (pORTARIADataSet.tbl_user.Rows.Count > 0) { tbl_userTableAdapter.atualizaUsuario(txtUsuario.Text.Trim(), nomeTextBox.Text.Trim(), situacaoCheckBox.Checked); if (alterarsenhacheck.Checked) { tbl_userTableAdapter.atualizaSenha(cripSenha, txtUsuario.Text.Trim()); MessageBox.Show("A senha foi alterada com sucesso", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else //novo usuario { tbl_userTableAdapter.insereUsuario(nomeTextBox.Text.Trim(), txtUsuario.Text.Trim(), cripSenha, situacaoCheckBox.Checked); MessageBox.Show("Senha: autoneum", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Information); } tbl_userProg tbl = new tbl_userProg(); tbl.excluiProgramas(txtUsuario.Text.Trim()); salvaAcessos(tevProg.Nodes, txtUsuario.Text.Trim()); listaUsuarios(); } catch (Exception err) { MessageBox.Show(err.Message, "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { tab = 0; tabControl1.SelectedIndex = tab; } }
public async Task <ActionResult> Login() { //统一登陆 if (WebConfigurationManager.AppSettings["LoginMode"] == "SSL") { var returnurl = Server.UrlEncode(HttpContext.Request.Url.AbsoluteUri); if (!Request.Url.AbsoluteUri.ToLower().Contains(WebConfigurationManager.AppSettings["LoginKey"].ToLower())) { Response.Redirect(WebConfigurationManager.AppSettings["LoginUrl"] + "?returnUrl=" + returnurl + "&systemName=" + WebConfigurationManager.AppSettings["SystemName"]); return(null); } byte[] _Key = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["Cryptokey"] ?? "HSJF!@#$12345678"); byte[] _IV = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["CryptoIV"] ?? "HSJF^%$#12345678"); var userinfo = Request.QueryString[WebConfigurationManager.AppSettings["LoginKey"]]; byte[] outputb = Convert.FromBase64String(userinfo); SymmCrypto symm = new SymmCrypto(_Key, _IV); var userstr = symm.DecryptToString(outputb, Encoding.UTF8); JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var luser = (LoginUser)jsonSerializer.Deserialize(userstr, typeof(LoginUser)); Microsoft.Owin.IOwinContext OwinContext = HttpContext.GetOwinContext(); //初始化用户管理相关 UserStore userStore = new UserStore(); UserDAL userdal = new UserDAL(); UserManager UserManager = new UserManager(userStore); Com.HSJF.Infrastructure.Identity.Model.User user = new Com.HSJF.Infrastructure.Identity.Model.User { UserName = luser.LoginName }; //byte[] _Key = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["Cryptokey"] ?? "HSJF!@#$12345678"); //byte[] _IV = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["CryptoIV"] ?? "HSJF^%$#12345678"); var newuser = UserManager.FindByName(luser.LoginName); user.Password = symm.DecryptToString(Convert.FromBase64String(newuser.Password)); if (!userdal.FindUser(user.UserName, Convert.ToBase64String(symm.EncryptFromString(user.Password)))) { ModelState.AddModelError("", "用户名不存在或者已被禁用!"); return(View()); } Microsoft.AspNet.Identity.Owin.SignInStatus SignInStatus = await PrivateLogin(user.UserName, user.Password); System.Web.HttpContext.Current.Session["_currentUser"] = UserManager.FindByName(user.UserName); return(RedirectToAction("Index", "Home")); } return(View()); }
public ActionResult ChangePassword() { if (WebConfigurationManager.AppSettings["LoginMode"] == "SSL") { byte[] _Key = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["Cryptokey"] ?? "HSJF!@#$12345678"); byte[] _IV = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["CryptoIV"] ?? "HSJF^%$#12345678"); var sysname = WebConfigurationManager.AppSettings["SystemName"]; var username = CurrentUser.UserName; SymmCrypto symm = new SymmCrypto(_Key, _IV); var safeuser = symm.EncryptFromString(username, Encoding.UTF8); var user = Convert.ToBase64String(safeuser); Response.Redirect(WebConfigurationManager.AppSettings["LoginUrl"] + "Account/ModifyPassword?username="******"&systemName=" + WebConfigurationManager.AppSettings["SystemName"]); return(null); } else { var model = new ChangePasswordViewModel(); return(View()); } }
/// <summary> /// This Method Decrypts Any Value To Original String With Specific Ways Described In The Type /// </summary> /// <example>string Encryption.Decrypt("BlaBlaBla",Ecryptiontypes.FormAuth);</example> public static string Decrypt(string strToDecrypt, Encryptiontypes type) { string back = ""; try { switch (type) { case Encryptiontypes.Mine: MyEncryption my = new MyEncryption(); back = my.Decrypt(strToDecrypt); break; case Encryptiontypes.FormAuth: Encryption en = new Encryption(); back = en.DecryptFrmAuth(strToDecrypt); break; case Encryptiontypes.Des: SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); back = sy.Decrypting(strToDecrypt, ""); break; case Encryptiontypes.Rijndal: SymmCrypto syy = new SymmCrypto(SymmCrypto.SymmProvEnum.Rijndael); back = syy.Decrypting(strToDecrypt, ""); break; default: break; } } catch { back = ""; } return(back); }
public string EncryptDes(string val) { SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); return(sy.Encrypting(val, "")); }
private bool validaControle() { string cripSenha = ""; if (txtSenha.Text.Trim() == "") { MessageBox.Show("O campo senha [Senha Atual] não pode estar em branco.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtSenha.Focus(); return(false); } if (txtNovaSenha.Text.Trim() == "") { MessageBox.Show("O campo nova senha não pode estar em branco.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtNovaSenha.Focus(); return(false); } if (txtConfirmar.Text.Trim() == "") { MessageBox.Show("O campo Confirmar não pode estar em branco.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtConfirmar.Focus(); return(false); } if (txtNovaSenha.Text != txtConfirmar.Text) { MessageBox.Show("O campo Confirmar não pode ser diferente do campo Nova Senha.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtConfirmar.Focus(); return(false); } try { SymmCrypto crip = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); cripSenha = crip.Encrypting(txtSenha.Text.Trim(), "6666"); tbl_userTableAdapter.buscaUsuario(pORTARIADataSet.tbl_user, lblViewUsr.Text); //dados do usuario if (pORTARIADataSet.tbl_user.Rows.Count > 0) // retornou alguma linha { if (pORTARIADataSet.tbl_user[0].senha.Trim() != cripSenha) //a senha bate { MessageBox.Show("Senha Inválida.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Usuário não localizado.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (System.Data.SqlClient.SqlException err) { MessageBox.Show(err.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (Exception err) { MessageBox.Show(err.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
public string DecryptDes(string val) { SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); return(sy.Decrypting(val, "AlHammadKey")); }
public async Task <ActionResult> Login(LoginViewModel usermodel) { if (!ModelState.IsValid) { return(View(usermodel)); } Microsoft.Owin.IOwinContext OwinContext = HttpContext.GetOwinContext(); //初始化用户管理相关 UserStore userStore = new UserStore(); UserDAL userdal = new UserDAL(); UserManager UserManager = new UserManager(userStore); //初始化权限管理相关 PermissionStore ps = new PermissionStore(); PermissionManager pm = new PermissionManager(ps); //登录 SignInManager signInManager = new SignInManager(UserManager, OwinContext.Authentication); Microsoft.AspNet.Identity.Owin.SignInStatus SignInStatus; string pass = usermodel.Password; string username = usermodel.LoginName; var user = new Com.HSJF.Infrastructure.Identity.Model.User { UserName = username, Password = pass }; byte[] _Key = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["Cryptokey"] ?? "HSJF!@#$12345678"); byte[] _IV = Encoding.UTF8.GetBytes(WebConfigurationManager.AppSettings["CryptoIV"] ?? "HSJF^%$#12345678"); SymmCrypto symm = new SymmCrypto(_Key, _IV); if (!userdal.FindUser(usermodel.LoginName, Convert.ToBase64String(symm.EncryptFromString(usermodel.Password)))) { ModelState.AddModelError("", "用户名不存在或者已被禁用!"); return(View()); } //域登陆 if (WebConfigurationManager.AppSettings["LoginMode"] == "LDAP") { LdapAuthentication ldap = new LdapAuthentication(); if (!ldap.IsAuthenticated(usermodel.LoginName, usermodel.Password)) { ModelState.AddModelError("", "用户名或者密码错误!"); return(View()); } var newuser = UserManager.FindByName(username); user.Password = symm.DecryptToString(Convert.FromBase64String(newuser.Password)); } SignInStatus = await PrivateLogin(user.UserName, user.Password); switch (SignInStatus) { //成功 case Microsoft.AspNet.Identity.Owin.SignInStatus.Success: //此处表示已经在startup 中配置 //标示 //System.Security.Claims.ClaimsIdentity identity = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); //授权登陆 //AutherticationManager.SignIn(new Microsoft.Owin.Security.AuthenticationProperties { IsPersistent = true }, identity); System.Web.HttpContext.Current.Session["_currentUser"] = signInManager.UserManager.FindByName(user.UserName); return(RedirectToAction("Index", "Home")); //锁定 case Microsoft.AspNet.Identity.Owin.SignInStatus.LockedOut: Response.Write("LockedOut!"); break; //要求验证 case Microsoft.AspNet.Identity.Owin.SignInStatus.RequiresVerification: Response.Write("RequiresVerification!"); break; //登录失败 case Microsoft.AspNet.Identity.Owin.SignInStatus.Failure: ModelState.AddModelError("", @"用户名或者密码错误!"); return(View()); } return(View()); }
public string DecryptRijndael(string val) { SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES); return(sy.Decrypting(val, "")); }
public string EncryptRijndael(string val) { SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.Rijndael); return(sy.Encrypting(val, "")); }