示例#1
0
文件: UserDAO.cs 项目: godlias/Olivia
        public int LogIn(string user, string password)
        {
            int id = -1;

            Connection con = new Connection();

            using (SqlCommand command = con.Fetch().CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = "select Id_User from[User] where Username=@Username AND Password=@Password";
                command.Parameters.Add("@Username", SqlDbType.VarChar);
                command.Parameters.Add("@Password", SqlDbType.VarChar);
                command.Parameters["@Username"].Value = user;
                command.Parameters["@Password"].Value = Utilizador.HashPassword(password);

                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                {
                    DataTable result = new DataTable();
                    adapter.Fill(result);

                    if (result.Rows.Count > 0)
                    {
                        DataRow row = result.Rows[0];
                        id = int.Parse(row["Id_User"].ToString());
                    }

                    con.Close();
                }
            }



            return(id);
        }
示例#2
0
        public IActionResult Register(CreateModel model)
        {
            if (ModelState.IsValid)
            {
                Utilizador u   = new Utilizador(-1, model.Username, Utilizador.HashPassword(model.Password), model.Email, 0, 1, model.Name);
                UserDAO    dAO = new UserDAO();

                bool flag = dAO.Insert(u);

                if (flag)
                {
                    return(RedirectToAction("Index", "Home", new { area = "" }));
                }
                else
                {
                    model.Username = "";
                }
            }
            return(View(model));
        }