public int AddAdmin(string name, string pwd) { try { Admin newAdmin = new Admin(); newAdmin.Name = name; Md5Helper md5 = new Md5Helper(); newAdmin.Password = md5.ConvertToMd5(pwd); context.AddToAdmin(newAdmin); context.SaveChanges(); return 1; } catch { return 0; } }
public int CheckAdmin(string name,string pwd) { AdminModel admin=new AdminModel(); admin=dal.GetAdminByName(name); if (admin==null) { return 0; } else { Md5Helper md5 = new Md5Helper(); string md5pwd = md5.ConvertToMd5(pwd); if (admin.Password == md5pwd) { return 1; } else { return 0; } } }
/// <summary> /// 修改管理员密码 /// </summary> /// <param name="id"></param> /// <param name="oldpwd"></param> /// <param name="newpwd"></param> /// <returns></returns> public int ChangeAdminPassword(int id,string oldpwd,string newpwd) { AdminModel admin=new AdminModel(); admin=dal.GetAdminById(id); Md5Helper md5 = new Md5Helper(); string oldmd5pwd = md5.ConvertToMd5(oldpwd); string newmd5pwd = md5.ConvertToMd5(newpwd); if (admin.Password == oldmd5pwd) { try { return dal.EditAdmin(id, admin.Name, newmd5pwd); } catch (Exception) { return 0; } } else { return 0; } }