Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        public byte[] HashPass(string password)
        {
            if (password == null)
            {
                throw new ArgumentNullException("Password is Null");
            }
            SymmCrypto symm = new SymmCrypto(_Key, _IV);

            return(symm.EncryptFromString(password));
        }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
 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);
         }
     }
 }
Ejemplo n.º 11
0
        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;
            }
        }
Ejemplo n.º 12
0
        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());
        }
Ejemplo n.º 13
0
 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());
     }
 }
Ejemplo n.º 14
0
        /// <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);
        }
Ejemplo n.º 15
0
        public string EncryptDes(string val)
        {
            SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES);

            return(sy.Encrypting(val, ""));
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        public string DecryptDes(string val)
        {
            SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES);

            return(sy.Decrypting(val, "AlHammadKey"));
        }
Ejemplo n.º 18
0
        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());
        }
Ejemplo n.º 19
0
        public string DecryptRijndael(string val)
        {
            SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.DES);

            return(sy.Decrypting(val, ""));
        }
Ejemplo n.º 20
0
        public string EncryptRijndael(string val)
        {
            SymmCrypto sy = new SymmCrypto(SymmCrypto.SymmProvEnum.Rijndael);

            return(sy.Encrypting(val, ""));
        }