Example #1
0
        private async void button2_Click(object sender, EventArgs e)
        {
            if (fallos == 3)
            {
                MessageBox.Show("Demasiados intentos...\nCerrando App");
                this.Close();
            }
            if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show("Favor de llenar los datos requeridos");
                txtUsername.Focus();
                return;
            }
            using (var db = new RRHHContext())
            {
                string user = txtUsername.Text.Trim().ToLower();
                string pass = txtPassword.Text.Trim();

                var u = await db.Credenciales.FirstOrDefaultAsync(x => x.UserName.ToLower().Equals(user));

                if (u == null)
                {
                    MessageBox.Show("Usuario no encontrado.");
                    Clear();
                    return;
                }

                var encrypted = CryptoServices.Encrypt(pass);
                if (!u.Password.Equals(encrypted))
                {
                    MessageBox.Show("ContraseƱa Incorrecta");
                    txtPassword.Clear();
                    txtPassword.Focus();
                    fallos += 1;
                    return;
                }
                MessageBox.Show("ContraseƱa Correcta");
                fallos = 0;
                SimpleModels.EmpleadoDataModel userdata = new SimpleModels.EmpleadoDataModel()
                {
                    Id       = u.EmpleadoId,
                    Nombre   = u.DatosEmpleado.Nombre,
                    Cedula   = u.DatosEmpleado.Cedula,
                    UserName = u.UserName
                };
                var mdi = new MDIs.MDI_User(db, userdata);
                this.Hide();
                mdi.ShowDialog();
                this.Show();
                Clear();
            }
        }
Example #2
0
 public static string Encrypt(string plaintext)
 {
     return(CryptoServices.Encrypt(plaintext));
 }