public ActionResult Index(LoginModel model) { var dao = new UserDao(); var res = dao.Login(model.UserName, Encriptor.MD5Hash(model.Password)); if (ModelState.IsValid) { switch (res) { case 0: ModelState.AddModelError("", CommonConstant.LOGIN_FAIL); break; case -1: ModelState.AddModelError("", CommonConstant.USER_IS_BLOCKED); break; default: var user = dao.GetNguoiDungByName(model.UserName); var userSession = new UserSession(); userSession.UserName = user.UserName; userSession.UserID = user.ID; userSession.UserRole = user.Role; Session.Add(CommonConstant.USER_SESSION, userSession); FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); return(RedirectToAction("Dashboard", "AdminHome")); } } return(View(model)); }
public ActionResult Create([Bind(Include = "ID,UserName,PassWord,Name,Address,Email,Phone,Image,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status")] User user) { Boolean check = false; var model = new UserDAO(); foreach (var item in model.UsLogin()) { if (user.UserName == item.UserName) { check = true; break; } } if (ModelState.IsValid) { if (check) { ModelState.AddModelError("", "UserName da ton tai"); } else { SetAlert("Them User thanh cong", "success"); user.PassWord = Encriptor.MD5Hash(user.PassWord); db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(user)); }
public ActionResult OlvidoContrasena(Usuario user) { BLL_Usuario usuarioBll = new BLL_Usuario(); Usuario usuario = usuarioBll.Listar(user.usuario); if (usuario != null) { string pass = Encriptor.GenerarPassword(10); MailMessage Correo = new MailMessage(); string mailFrom = WebConfigurationManager.AppSettings["from_mail"]; string usuarioMail = WebConfigurationManager.AppSettings["usuario_mail"]; string passMail = WebConfigurationManager.AppSettings["pass_mail"]; Correo.From = new MailAddress(mailFrom); Correo.To.Add(usuario.correo); Correo.Subject = "Password"; Correo.Body = "pass: "******"smtp.gmail.com"; ServerEmail.Port = 587; ServerEmail.EnableSsl = true; Bitacora b = new Bitacora(); b.fecha = DateTime.Now; b.mensaje = "Recupero de pass"; b.Usuario = usuario; try { ServerEmail.Send(Correo); usuario.password = pass; usuarioBll.Grabar(usuario); b.Tipo = TipoLog.INFO; } catch (Exception e) { b.Tipo = TipoLog.ERROR; Console.Write(e); } bitacoraBll.Grabar(b); Correo.Dispose(); return(View(@"~\Views\Login\CambioPassOK.cshtml")); } else { ViewBag.existe = "Usuario inexistente"; return(View()); } }
public ActionResult Edit([Bind(Include = "ID,UserName,PassWord,Name,Address,Email,Phone,Image,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status")] User user) { if (ModelState.IsValid) { SetAlert("Sua thanh cong", "success"); user.PassWord = Encriptor.MD5Hash(user.PassWord); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new UserDAO(); var res = dao.Login(model.UserName, Encriptor.MD5Hash(model.Password)); if (res == 1) { var user = dao.GetByID(model.UserName); var UserSession = new UserLogin(); UserSession.UserName = user.UserName; UserSession.UserID = user.ID; Session.Add(CommonConstants.User_Session, UserSession); Session["UserID"] = user.ID; return(RedirectToAction("Index", "Home")); } else { if (res == -1) { ViewBag.error = "Mật khẩu nhập vào không đúng"; return(View("Index")); } else { if (res == 0) { ViewBag.error = "Tài khoản không tồn tại"; return(View("Index")); } else { ViewBag.error = "Tài khoản bị khóa"; return(View("Index")); } } } } else { ViewBag.error = "Login thất bại"; return(View("Index")); } }
public string checkLoggin(string userName, string passWord) { //assigning username to variable string username = userName; string UserLevel=""; //assigning encripted password form text box & Encript Encriptor enc = new Encriptor(); string password = enc.encript(passWord); // encripted one OdbcDataAdapter adpNameList = DB_Connect.ExecuteQuery("SELECT USER_USERNAME, ROLE_CODE FROM users_mast WHERE USER_USERNAME ='******' AND USER_PASSWORD = '******'"); adpNameList.SelectCommand.CommandType = CommandType.Text; DataSet userList = new DataSet(); adpNameList.Fill(userList); if (userList.Tables[0].Rows.Count == 1) { Console.Beep(); for (int i = 0; i < userList.Tables[0].Rows.Count; i++) { //get the user level from DB according to user name UserLevel = userList.Tables[0].Rows[i][1].ToString(); } } else { UserLevel = "error"; } return UserLevel; }
private void Button1_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBox1.Text) && !string.IsNullOrWhiteSpace(textBox2.Text) && !string.IsNullOrWhiteSpace(textBox3.Text)) { string user = textBox1.Text, login = textBox2.Text, pass = textBox3.Text; if (textBox1.Text.Contains(' ')) { user = textBox1.Text.Replace(" ", ""); } if (textBox2.Text.Contains(' ')) { login = textBox2.Text.Replace(" ", ""); } if (textBox3.Text.Contains(' ')) { pass = textBox3.Text.Replace(" ", ""); } using (RegistryKey key = Registry.CurrentUser.CreateSubKey($@"Software\SteamProfiles\{login}")) { user = Encriptor.Encypter(user); login = Encriptor.Encypter(login); pass = Encriptor.Encypter(pass); key.SetValue("UserName", user); key.SetValue("Login", login); key.SetValue("Password", pass); } textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); MessageBox.Show(Success); } else { MessageBox.Show(FieldsError); } }
private void Button1_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBox1.Text)) { if (!string.IsNullOrWhiteSpace(textBox2.Text) && string.IsNullOrWhiteSpace(textBox3.Text)) { using RegistryKey reg = Registry.CurrentUser.OpenSubKey($@"SOFTWARE\SteamProfiles\{textBox1.Text}", true); if (reg != null) { Registry.CurrentUser.OpenSubKey($@"SOFTWARE\SteamProfiles\{textBox1.Text}", true).SetValue("UserName", Encriptor.Encypter(textBox2.Text)); MessageBox.Show(Done); } } if (!string.IsNullOrWhiteSpace(textBox2.Text) && !string.IsNullOrWhiteSpace(textBox3.Text)) { using RegistryKey reg = Registry.CurrentUser.OpenSubKey($@"SOFTWARE\SteamProfiles\{textBox1.Text}", true); if (reg != null) { Registry.CurrentUser.OpenSubKey($@"SOFTWARE\SteamProfiles\{textBox2.Text}", true).SetValue("UserName", Encriptor.Encypter(textBox2.Text)); Registry.CurrentUser.OpenSubKey($@"SOFTWARE\SteamProfiles\{textBox2.Text}", true).SetValue("Password", Encriptor.Encypter(textBox3.Text)); MessageBox.Show(Done); } } if (!string.IsNullOrWhiteSpace(textBox3.Text) && string.IsNullOrWhiteSpace(textBox2.Text)) { using RegistryKey reg = Registry.CurrentUser.OpenSubKey($@"SOFTWARE\SteamProfiles\{textBox1.Text}", true); if (reg != null) { reg.SetValue("Password", Encriptor.Encypter(textBox3.Text)); MessageBox.Show(Done); } } } else { MessageBox.Show(LoginError); } }
protected void btnChange_Click(object sender, EventArgs e) { Utility utl = new Utility(); //get user level after compair passwords string userLevel = utl.checkLoggin(Session["user"].ToString(), txtCurPas.Text); if (userLevel != "error") { if (txtNewPass.Text == txtConfPass.Text) { //assigning encripted password form text box & Encript Encriptor enc = new Encriptor(); string password = enc.encript(txtConfPass.Text.ToString()); //DB_Connect.InsertQuery("UPDATE users_mast SET USER_PASSWORD='******' WHERE USER_USERNAME='******'"); DB_Connect.InsertQuery("UPDATE users_mast SET USER_PASSWORD='******' WHERE USER_USERNAME='******'"); lblstatus.Text = "Password Changed."; } else { lblstatus.Text = "Passwords Doesnt Match"; } } else { lblstatus.Text = "Current Password Invalid"; } }
public void ejecutarABMUsuario(string nombreStored) { if (MessageBox.Show("Está seguro que desea continuar con la operación?", "FOUR SIZONS - FRBA Hoteles", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // se agrega el código en un try / catch para poder capturar los errores try { // se crea un nuevo conector, se asigna el nombre del stored y con execute se crea el nuevo comando sql Conexion con = new Conexion(); Encriptor encriptor = new Encriptor(); con.strQuery = nombreStored; con.execute(); con.command.CommandType = CommandType.StoredProcedure; // se agregan los parámetros al stored procedure con.command.Parameters.Add("@username", SqlDbType.NVarChar).Value = txt_usuario.Text; string msg = encriptor.Encrypt(txt_password.Text); con.command.Parameters.Add("@password", SqlDbType.NVarChar).Value = encriptor.Encrypt(txt_password.Text); con.command.Parameters.Add("@rolNombre", SqlDbType.NVarChar).Value = cb_rol.Text; con.command.Parameters.Add("@nombre", SqlDbType.NVarChar).Value = txt_nombre.Text; con.command.Parameters.Add("@apellido", SqlDbType.NVarChar).Value = txt_apellido.Text; con.command.Parameters.Add("@tipoDoc", SqlDbType.NVarChar).Value = cb_tipo_documento.Text; con.command.Parameters.Add("@numDoc", SqlDbType.Int).Value = txt_nro_documento.Text; con.command.Parameters.Add("@mail", SqlDbType.NVarChar).Value = txt_mail.Text; con.command.Parameters.Add("@telefono", SqlDbType.NVarChar).Value = txt_telefono.Text; con.command.Parameters.Add("@direccion", SqlDbType.NVarChar).Value = txt_direccion.Text; con.command.Parameters.Add("@fechanac", SqlDbType.DateTime).Value = dt_fecha_nac.Value.ToShortDateString(); if (modoABM == "DLT") { con.command.Parameters.Add("@estado", SqlDbType.Bit).Value = 0; } else if (modoABM == "UPD") { con.command.Parameters.Add("@estado", SqlDbType.Bit).Value = 1; } // se abre la conexión con la base de datos, se ejecuta y se cierra con.openConection(); con.command.ExecuteNonQuery(); con.closeConection(); if (modoABM == "INS") { con.strQuery = "FOUR_SIZONS.altaUserXHot"; con.execute(); con.command.CommandType = CommandType.StoredProcedure; if (hotel == 0) { hotel = hotelppal; } // se agregan los parámetros al stored procedure con.command.Parameters.Add("@hotId", SqlDbType.Decimal).Value = hotel; con.command.Parameters.Add("@usuario", SqlDbType.NVarChar).Value = txt_usuario.Text; if (modoABM == "DLT") { con.command.Parameters.Add("@estado", SqlDbType.Bit).Value = 0; } else { con.command.Parameters.Add("@estado", SqlDbType.Bit).Value = 1; } // se abre la conexión con la base de datos, se ejecuta y se cierra con.openConection(); con.command.ExecuteNonQuery(); con.closeConection(); } MessageBox.Show("Operación exitosa", "FOUR SIZONS - FRBA Hoteles", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { error = 1; MessageBox.Show("Error al completar la operación. " + ex.Message, "FOUR SIZONS - FRBA Hoteles", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { error = 1; MessageBox.Show("No se ha completado la operación", "FOUR SIZONS - FRBA Hoteles", MessageBoxButtons.OK, MessageBoxIcon.Information); } }