Beispiel #1
0
 public bool Update(string Account, string Password, string newPassword)
 {
     try
     {
         using (var db = new UserContext())
         {
             var PasswordMD5 = MD5Creating.EncryptWithMD5(Password);
             var b           = db.Users.Count(a => a.Account.Equals(Account) && a.Password.Equals(PasswordMD5));
             if (b != 0) //查账号和原密码
             {
                 var c = db.Users.Where(a => a.Account.Equals(Account));
                 PasswordMD5 = MD5Creating.EncryptWithMD5(newPassword);
                 c.FirstOrDefault().Password = PasswordMD5;
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #2
0
 public bool Insert(string Account, string Password, string Nickname)
 {
     try
     {
         using (var db = new UserContext())
         {
             if (db.Users.Count(a => a.Account.Equals(Account)) == 0) //判断账号是否存在
             {
                 var PasswordMD5 = MD5Creating.EncryptWithMD5(Password);
                 db.Users.AddRange(new List <User>()
                 {
                     new User()
                     {
                         Account = Account, Password = PasswordMD5, Nickname = Nickname
                     }
                 });
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
 public User Access(string Account, string Password)
 {
     try
     {
         using (var db = new UserContext())
         {
             var PasswordMD5 = MD5Creating.EncryptWithMD5(Password);
             var b           = db.Users.Where(a => a.Account.Equals(Account) && a.Password.Equals(PasswordMD5)).FirstOrDefault(); //选对应昵称
             return(b);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
        internal static void Main()
        {
            try
            {
                using (var db = new UserContext())
                {
                    var b = db.Users.Count(a => a.Account.Equals("admin"));  //检查是否有管理员账户
                    if (b == 0)
                    {
                        var AdminMD5 = MD5Creating.EncryptWithMD5("admin");
                        db.Users.AddRange(new List <User>()
                        {
                            new User()
                            {
                                Account = "admin", Password = AdminMD5, Nickname = "admin"
                            }
                        });                                                                                                                //添加管理员账户
                        db.SaveChanges();
                    }
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show("发生严重错误:" + ex);
                Application.Exit();
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            LoginForm login = new LoginForm();

            //界面转换
            login.ShowDialog();
            if (login.DialogResult == DialogResult.OK)
            {
                string Acc = login.Acc;
                login.Dispose();
                login.Close();
                MainForm m = new MainForm(Acc);
                Application.Run(m);
            }
        }