예제 #1
0
        public ActionResult Login(User_Login user)
        {
            if (user.username != null && user.Password != null)
            {
                var login  = db.User_Login.Where(a => a.username == user.username).Single();
                int userid = Convert.ToInt32(login.userid);
                Session["userid"] = userid.ToString();
                Session["Name"]   = login.username;
                var    UsersInRole = db.UsersInRoles.Where(b => b.UserId == userid.ToString().Single());
                string rolename    = UsersInRole.ToString();
                Session["rolename"] = rolename;
                if (UsersInRole != null)
                {
                    if (rolename == "Admin")
                    {
                        Session["rolename"] = "Admin";

                        return(RedirectToAction("Admin", "Admin"));
                    }
                }
                else if (rolename == "user")
                {
                    Session["rolename"] = "User";
                    return(RedirectToAction("Admin", "Admin"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Login data is incorrect");
            }


            return(View(user));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            User_Login user_Login = db.User_Login.Find(id);

            db.User_Login.Remove(user_Login);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "UserLogin_ID,UserLogin_CreatDT,UserLogin_Guid,UserLogin_Name,UserLogin_PassWord,UserLogin_State")] User_Login user_Login)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user_Login).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user_Login));
 }
        public ActionResult Index(User_Login ul)
        {
            bool status = false;

            db.Insert_User_login(ul);
            status = true;

            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult Create([Bind(Include = "UserLogin_ID,UserLogin_CreatDT,UserLogin_Guid,UserLogin_Name,UserLogin_PassWord,UserLogin_State")] User_Login user_Login)
        {
            if (ModelState.IsValid)
            {
                db.User_Login.Add(user_Login);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user_Login));
        }
예제 #6
0
 public IActionResult Index(User_Login user)
 {
     if (user.IsLoggedIn)
     {
         return(View());
     }
     else
     {
         return(Content("F**k af, du skal logge ind!"));
     }
 }
예제 #7
0
    private void InsertUpdateAgent()
    {
        User_Login objUser_Login = new User_Login();

        try
        {
            if (!fuAgentLogo.HasFile)
            {
                if (hfcommunicationlogo.Value == "")
                {
                    lbllogoman.Text = "Please upload logo";
                    return;
                }
            }
            objUser_Login.UserLoginId         = Convert.ToInt32(hfAgentLoginId.Value);
            objUser_Login.UserCompany         = ddlAgentCompany.SelectedIndex > 0 ? Convert.ToInt32(ddlAgentCompany.SelectedValue) : 0;
            objUser_Login.UserRole            = Convert.ToInt32(ddlRole.SelectedValue);
            objUser_Login.LoginId             = txtEmailId.Text;
            objUser_Login.Password            = txtPassword.Text;
            objUser_Login.can_change_password = chkChangePassword.Checked;
            objUser_Login.active_code         = 0;
            objUser_Login.UserEmail           = txtEmailId.Text;
            objUser_Login.UserPhone           = txtMobileNumber.Text;
            objUser_Login.UserType            = 2;
            objUser_Login.UserName            = txtCompanyName.Text;
            objUser_Login.BranchId            = ddlBranch.SelectedValue;
            objUser_Login.ProvinceId          = ddlProvince.SelectedValue;
            objUser_Login.CityId           = ddlCities.SelectedValue;
            objUser_Login.ticket_fee_agent = txtTicketPrice.Text != "" ? Convert.ToDecimal(txtTicketPrice.Text) : 0;
            objUser_Login.TicketConsId     = ddlMappingcons.SelectedIndex > 0 ? Convert.ToDecimal(ddlMappingcons.SelectedValue) : 0;

            int nResult = _objBALUserManager.InsertUpdateUserLogin(objUser_Login);
            if (nResult == -1)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Login id already exist.");
            }
            else if (nResult == -2)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Email  id already exist.");
            }
            else if (nResult == -3)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Mobile no already exist.");
            }
            else
            {
                InsertUpdateAgentDetails(nResult);
            }
        }
        catch (Exception ex)
        {
            labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", ex.Message);
        }
    }
        public void CheckLoginStart()
        {
            User_Login user_Login = new User_Login();

            try
            {
                if (Session["UsernameOrdinary"] != null || Session["UsernameOrdinary"].ToString() != "")
                {
                    user_Login = (User_Login)Session["UsernameOrdinary"];
                    //string[] vs = Session["Username"].ToString().Split(',');
                    var list = (from n in db.User_Login
                                join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                                into JionedEmpDept
                                from a in JionedEmpDept.DefaultIfEmpty()
                                where n.UserLogin_Name == user_Login.UserLogin_Name && n.UserLogin_PassWord == user_Login.UserLogin_PassWord
                                select new
                    {
                        权限 = a.UserCard_GmLevel,
                        状态 = n.UserLogin_State
                    });            //内连接
                    if (list.Count() > 0)
                    {
                        foreach (var s in list)
                        {
                            if (s.状态 == true)
                            {
                                start = true;
                                //if (s.权限 == 0)
                                //{
                                //    start = true;
                                //}
                                //else
                                //{
                                //    start = false;
                                //}
                            }
                            else
                            {
                                start = false;
                            }
                        }
                    }
                }
                else
                {
                    start = false;
                }
            }
            catch (Exception e)
            {
                start = false;
            }
        }
        public async Task <Users> GetUserByName(User_Login users)
        {
            try
            {
                FilterDefinition <Users> filter = Builders <Users> .Filter.Eq("Username", users.Username);

                return(await db.Users.Find(filter).FirstOrDefaultAsync());
            }
            catch
            {
                throw;
            }
        }
예제 #10
0
 private void btnUser_Click(object sender, EventArgs e)
 {
     if (CurrentInfo.authority == Authority.Empty)
     {
         User_Login frm = new User_Login();
         frm.sendLogin += Login;
         frm.ShowDialog();
     }
     else
     {
         LogOut();
     }
 }
예제 #11
0
        //Enter the application on click eventhandler
        private void btn_enter_application_Click(object sender, EventArgs e)
        {
            //Close the current form
            this.Hide();

            //Make an instance of the new form
            var Option_Screen = new User_Login();

            Option_Screen.Closed += (s, args) => this.Close();

            //Open the new form
            Option_Screen.Show();
        }
예제 #12
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_Login user_Login = db.User_Login.Find(id);

            if (user_Login == null)
            {
                return(HttpNotFound());
            }
            return(View(user_Login));
        }
예제 #13
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         User_Login user_Login = db.User_Login.Find(id);
         db.User_Login.Remove(user_Login);
         db.SaveChanges();
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "无法保存更改。再试一次,如果问题仍然存在,请参见系统管理员。");
     }
     return(RedirectToAction("Index"));
 }
예제 #14
0
        public object Login(User_Login value)
        {
            try
            {
                //执行业务操作
                Dm_ResultDefault result = User_LoginBLO.Login(value);

                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #15
0
        // GET: User_Login/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User_Login user_Login = db.User_Login.Find(id);

            if (user_Login == null)
            {
                return(HttpNotFound());
            }
            return(View(user_Login));
            //return RedirectToAction("Index", "Admin");
        }
예제 #16
0
 public ActionResult Edit([Bind(Include = "UserLogin_ID,UserLogin_CreatDT,UserLogin_Guid,UserLogin_Name,UserLogin_PassWord,UserLogin_State")] User_Login user_Login)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(user_Login).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "无法保存更改。再试一次,如果问题仍然存在,请参见系统管理员。");
     }
     return(View(user_Login));
 }
    private void InsertUpdateStaff()
    {
        User_Login objUser_Login = new User_Login();

        try
        {
            objUser_Login.UserLoginId         = Convert.ToInt32(hfStaffLoginId.Value);
            objUser_Login.UserCompany         = Convert.ToInt32(Session["CompanyId"]);
            objUser_Login.UserRole            = 6;
            objUser_Login.LoginId             = txtStaffLoginId.Text;
            objUser_Login.Password            = txtPassWord.Text;
            objUser_Login.can_change_password = chkChangePassword.Checked;
            objUser_Login.active_code         = 0;
            objUser_Login.UserEmail           = txtEmailId.Text;
            objUser_Login.UserPhone           = txtMobileNumber.Text;
            objUser_Login.UserType            = 3;
            objUser_Login.UserName            = txtFirstName.Text + " " + txtLastName.Text;

            objUser_Login.BranchId   = "0"; //ddlBranch.SelectedValue;
            objUser_Login.ProvinceId = "0"; //ddlProvince.SelectedValue;
            objUser_Login.CityId     = "0"; // ddlCities.SelectedValue;

            int nResult = _objBALUserManager.InsertUpdateUserLogin(objUser_Login);
            if (nResult == -1)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Login id already exist.");
            }
            else if (nResult == -2)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Email  id already exist.");
            }
            else if (nResult == -3)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Mobile no already exist.");
            }
            else
            {
                InsertUpdateStaffPersonalDetails(nResult);
            }
        }
        catch (Exception ex)
        {
            labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", ex.Message);
        }
    }
예제 #18
0
        public ActionResult TestComment()
        {
            User_Login user_Login  = new User_Login();
            var        user_Logins = from a in db.User_Login
                                     where a.UserLogin_ID == 1
                                     select a;

            foreach (var a in user_Logins)
            {
                user_Login = a;
            }
            Session["User"] = user_Login;//user_Login;
            User_Login login = (User_Login)Session["User"];

            ViewBag.ID         = login.UserLogin_ID;
            ViewBag.Article_ID = 1; //文章id
            return(View());         //评论模块
        }
예제 #19
0
        public static bool LoginCheck(int id, String pass, String userType)
        {
            DBDataContext db = new DBDataContext();
            User_Login    lg = new User_Login();

            var ob = from p in db.User_Logins
                     where p.User_id == id && p.Pass == pass && p.User_type == userType
                     select p;

            if (ob.Any())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #20
0
        public ActionResult Admin(User_Login user)
        {
            if (user.username != null && user.Password != null)
            {
                var login = (from l in db.User_Login where l.username == user.username select new { l.userid }).ToList();
                //db.User_Login.Where(a => a.username == user.username).Single();
                if (login.Count > 0)
                {
                    Session["userid"]   = login[0].userid;
                    Session["UserName"] = user.username;
                    int uid = Convert.ToInt32(Session["userid"]);
                    // int userid = Convert.ToInt32(login.userid);
                    //Session["userid"] = userid.ToString();
                    //string name = login.username.ToString();
                    //Session["UserName"] = name;


                    var    UsersInRole = (from k in db.UsersInRoles where k.UserId == uid select new { k.UserName }).ToList(); //db.UsersInRoles.Where(b => b.UserId == userid.ToString().FirstOrDefault());
                    string rolename    = UsersInRole[0].UserName;
                    Session["rolename"] = rolename;
                    if (UsersInRole != null)
                    {
                        if (rolename == "admin")
                        {
                            Session["rolename"] = "admin";

                            return(RedirectToAction("Admin", "Admin"));
                        }
                    }
                    else if (rolename == "user")
                    {
                        Session["rolename"] = "User";
                        return(RedirectToAction("Admin", "Admin"));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Login data is incorrect");
            }


            return(View(user));
        }
예제 #21
0
        private void Panel_Login_Loaded(object sender, RoutedEventArgs e)
        {
            User_Login.Focus();
            BDConexion verifyUser = new BDConexion();

            verifyUser.SetCadenaConexion("127.0.0.1", "3306", "root", "", "bd_ipopreg_iiee");
            verifyUser.SetCadenaTable("docente");
            MySqlConnection UserList = new MySqlConnection(verifyUser.CadenaConexion());

            try
            {
                UserList.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            UserList.Close();
        }
예제 #22
0
    private void InsertUpdateAgent()
    {
        User_Login objUser_Login = new User_Login();

        try
        {
            objUser_Login.UserLoginId         = Convert.ToInt32(Session["loginId"]);
            objUser_Login.UserCompany         = ddlAgentCompany.SelectedIndex > 0 ? Convert.ToInt32(ddlAgentCompany.SelectedValue) : 0;
            objUser_Login.UserRole            = Convert.ToInt32(ddlRole.SelectedValue);
            objUser_Login.LoginId             = txtAgentLoginId.Text;
            objUser_Login.Password            = txtPassWord.Text;
            objUser_Login.can_change_password = chkChangePassword.Checked;
            objUser_Login.active_code         = 0;
            objUser_Login.UserEmail           = txtEmailId.Text;
            objUser_Login.UserPhone           = txtMobileNumber.Text;
            objUser_Login.UserName            = txtCompanyName.Text;
            objUser_Login.BranchId            = "0";
            objUser_Login.ProvinceId          = ddlProvince.SelectedValue;
            objUser_Login.CityId = ddlCities.SelectedValue;

            int nResult = _objBALUserManager.InsertUpdateUserLogin(objUser_Login);
            if (nResult == -1)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Login id already exist.");
            }
            else if (nResult == -2)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Email  id already exist.");
            }
            else if (nResult == -3)
            {
                labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", "This Mobile no already exist.");
            }
            else
            {
                InsertUpdateAgentDetails(nResult);
            }
        }
        catch (Exception ex)
        {
            labelError.Text = _objBOUtiltiy.ShowMessage("danger", "Error", ex.Message);
        }
    }
예제 #23
0
        private void Panel_Login_Loaded(object sender, RoutedEventArgs e)
        {
            User_Login.Focus();
            try
            {
                loginAsist.AutoSetCadenaConexion(datos);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Se creara una nueva tabla de datos de conexion de la Base de Datos\n\n{ex.Message}", "No se encontro el Archivo de Conexión");
                //datos se carga de XML

                loginAsist.ConfigDefault(datos);
                loginAsist.AutoSetCadenaConexion(datos);
            }

            MySqlConnection Login_Con = new MySqlConnection(loginAsist.CadenaConexion());

            try
            {
                Login_Con.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (Login_Con.State == ConnectionState.Open)
            {
                MySqlDataReader reader = loginAsist.ListUser(Login_Con);
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        string[] row = { reader.GetString(0), reader.GetString(1) };
                        UserList_Login.Items.Add($"{row[0]} {row[1]}");
                    }
                }
            }
            Login_Con.Close();
            MySqlConnection.ClearPool(Login_Con);
        }
예제 #24
0
        public async Task <IActionResult> Login(User_Login user)
        {
            var users = await _dataAccessProvider.GetUserByName(user);

            if (users == null)
            {
                return(Content("No Information entered in text boxes" + user.Username));
            }

            if (BCrypt.Net.BCrypt.Verify(user.Password, users.Password))
            {
                //Sådan man bliver redirected til posting siden.
                //return Content("Password is correct");
                user.IsLoggedIn = true;

                return(RedirectToAction("Index", "Home", user));
            }

            return(Content("Your password Or Username was not found or wrong."));
        }
        public JsonResult UserLoginImg()
        {
            User_Login user_Login = new User_Login();

            user_Login = (User_Login)Session["UsernameOrdinary"];
            var list = (from n in db.User_Login
                        join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                        into JionedEmpDept
                        from a in JionedEmpDept.DefaultIfEmpty()
                        where n.UserLogin_Name == user_Login.UserLogin_Name && n.UserLogin_PassWord == user_Login.UserLogin_PassWord
                        select new
            {
                权限 = a.UserCard_GmLevel,
                状态 = n.UserLogin_State,
                头像 = a.UserCard_ChatHeadImg,
                用户名 = n.UserLogin_Name,
                昵称 = a.UserCard_Nickname
            });

            return(Json(list.ToList(), JsonRequestBehavior.AllowGet));
        }
예제 #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            User_Login ul = new User_Login();

            ul.Login_Name     = context.UserName;
            ul.Login_PassWord = context.Password;
            ul.Login_Ip       = "";
            Dm_ResultDefault dm = User_LoginBLO.Logins(ul);

            //if (context.UserName == "Aju" && context.Password == "Aju_password")
            if (dm.Result == 1)
            {
                context.Result = new GrantValidationResult(
                    subject: context.UserName,
                    authenticationMethod: OidcConstants.AuthenticationMethods.Password);
            }
            else
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "无效的秘钥");
            }
            return(Task.FromResult(""));
        }
예제 #27
0
        public static void userSignUp(String userName, String pass, String email, String userType)
        {
            DBDataContext db = new DBDataContext();
            User_Login    lg = new User_Login();

            lg.Pass      = pass;
            lg.User_type = userType;

            db.User_Logins.InsertOnSubmit(lg);
            db.SubmitChanges();

            Customer cm = new Customer();

            cm.Email         = email;
            cm.Customer_type = userType;
            db.Customers.InsertOnSubmit(cm);
            db.SubmitChanges();

            Address ad = new Address();

            db.Addresses.InsertOnSubmit(ad);
            db.SubmitChanges();
        }
예제 #28
0
        public ActionResult Login(Customers customers)
        {
            if (ModelState.IsValid)
            {
                if (db.Customers.Any(c => c.Id == customers._id) &&
                    db.Customers.Any(c => c.Password == customers._password))
                {
                    var cus         = db.Customers.Find(customers._id);
                    var cus_session = new User_Login();
                    cus_session._userName = cus.Id;
                    cus_session._password = cus.Password;

                    Session.Add("USER_SESSION", cus_session);

                    return(RedirectToAction("Index", "Cart"));
                }
                else
                {
                    ModelState.AddModelError("", "User hoặc Password không đúng.");
                }
            }

            return(View());
        }
예제 #29
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType     = "text/plain";
            context.Response.Buffer          = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            string active       = HttpContext.Current.Request["action"];
            string Account      = context.Request["Account"] == null?"": context.Request["Account"].ToLower(); //账户
            string Pwd          = context.Request["Pwd"] == null?"": context.Request["Pwd"];                   //密码
            string ls_checkcode = context.Request["code"] == null?"": context.Request["code"].ToLower();       //验证码
            string ls_Msg       = string.Empty;
            string ls_dbref     = string.Empty;

            switch (active)
            {
            case "login":    //登录
                try
                {
                    string IPAddress = RequestHelper.GetIPAddress();

                    string ls_code = HttpContext.Current.Session["dt_session_code"].ToString().ToLower();
                    if (ls_checkcode != ls_code)
                    {
                        ls_Msg = "1";    //验证码输入不正确
                    }
                    else
                    {
                        User_Login user_Login = db.User_Login.Find(Account);

                        string ls_name = user_Login == null ? null : user_Login.Login_name;
                        string ls_pwd  = user_Login == null ? null : user_Login.Login_password;

                        if (string.IsNullOrEmpty(ls_name))
                        {
                            ls_Msg = "4";     //账户或密码不对
                        }
                        if (ls_name == Account && ls_pwd == Pwd)
                        {
                            context.Session["Account"] = Account;
                            context.Session["Pwd"]     = Pwd;
                            context.Session["IP"]      = IPAddress;
                            try
                            {
                                #region 将用户信息存入用户信息表
                                User_Login_Info user_Login_Info = new User_Login_Info();
                                user_Login_Info.IP       = IPAddress;
                                user_Login_Info.PassWord = Base64Helper.EncodeBase64(Pwd);
                                user_Login_Info.UserId   = context.Request["ASP.NET_SessionId"];
                                user_Login_Info.UserName = Account;
                                user_Login_Info.DateTime = DateTime.Now.ToString();
                                db.User_Login_Info.Add(user_Login_Info);
                                db.SaveChanges();

                                #endregion
                            }
                            catch (Exception e)
                            {
                            }

                            ls_Msg = "3";    //验证成功
                        }
                    }
                }
                catch (Exception ex)
                {
                    ls_Msg = ex.Message;
                }
                context.Response.Write(ls_Msg);
                context.Response.End();

                break;
            }
        }
        public int LoginAdmin(string username, string password)
        {
            var state = 0;

            if (db.User_Login.Where(x => x.UserLogin_Name == username).ToList().Count > 0)
            {
                List <User_Login> user = db.User_Login.Where(x => x.UserLogin_Name == username).ToList();
                if (user.Select(x => x.UserLogin_PassWord == password).Count() > 0)
                {
                    var list = (from n in user
                                join a in db.User_Card on n.UserLogin_ID equals a.UserLogin_ID
                                into JionedEmpDept
                                from a in JionedEmpDept.DefaultIfEmpty()
                                select new
                    {
                        权限 = a.UserCard_GmLevel,
                        状态 = n.UserLogin_State
                    });            //内连接
                    foreach (var s in list)
                    {
                        if (s.状态 == true)
                        {
                            if (s.权限 == 0)
                            {
                                state = 1;
                            }
                            else
                            {
                                state = 3;
                            }
                        }
                        else
                        {
                            state = 4;
                        }
                    }
                    //state = 1;//登录成功
                    if (state == 1)
                    {
                        /*
                         * if (Request.Cookies.Get("username") != null)//Request.Cookies["username"]!=null
                         * {
                         *  //Cookie已经存在
                         * }*/
                        //return RedirectToAction( "_operator", "operatorInfo" );
                        //User_Login user_Login = db.User_Login.Where(x => x.UserLogin_Name == username);
                        User_Login user_Login  = new User_Login();
                        var        user_Logins = from a in db.User_Login
                                                 where a.UserLogin_Name == username && a.UserLogin_PassWord == password
                                                 select a;
                        foreach (var a in user_Logins)
                        {
                            user_Login = a;
                        }
                        Session["Username"] = user_Login;
                        /*使用Cookie*/

                        //cookie.Value = "用户名";//单值
                        cookie.Values["username"] = HttpUtility.UrlEncode(username);
                        //cookie.Values["password"] = HttpUtility.UrlEncode(password);//多值
                        //cookie.Expires = DateTime.MaxValue;//过期时间
                        cookie.Expires = DateTime.Now.AddHours(1);
                        Response.Cookies.Add(cookie);
                        roles.SetRole(username, "Admin");
                    }
                    else
                    {
                        Response.Cookies["User"].Values["username"] = null;
                        Session["Username"] = null;
                        Session.RemoveAll();
                        Session.Clear();
                    }
                }
                else
                {
                    state = 2;//密码错误
                    Session.RemoveAll();
                    Session.Clear();
                }
            }
            else
            {
                state = 0;//无此用户
                Session.RemoveAll();
                Session.Clear();
            }
            return(state);
        }