AdminUserBll.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Web;
  7. using CP.Cache;
  8. using CP.Common;
  9. using CP.Model;
  10. using System.Data;
  11. using NIU.Core;
  12. namespace CP.Business
  13. {
  14. public class AdminUserBll
  15. {
  16. public static AdminUser GetBy(string userName, string pwd)
  17. {
  18. pwd = Encryption.MD5(pwd);
  19. var dc = new DataConnect();
  20. var model = dc.db.SingleOrDefault<AdminUser>($"where userName='{userName}' and pwd='{pwd}'");
  21. return model;
  22. }
  23. public static void PwdEdit(long id, string oldPwd, string pwd, string cfmPwd)
  24. {
  25. var dc = new DataConnect();
  26. var entity = dc.db.SingleOrDefault<AdminUser>(id);
  27. if (entity == null)
  28. throw new OperationExceptionFacade("操作失败:数据不存在");
  29. if (pwd.Length < 6)
  30. throw new OperationExceptionFacade("操作失败:密码至少由6个字符组成");
  31. if (cfmPwd != pwd)
  32. throw new OperationExceptionFacade("操作失败:两次输入的密码不相同");
  33. if (entity.Pwd != Encryption.MD5(oldPwd))
  34. throw new OperationExceptionFacade("操作失败:原密码错误");
  35. entity.Pwd = Encryption.MD5(pwd);
  36. if (dc.db.Update(entity) <= 0)
  37. throw new OperationExceptionFacade("操作失败");
  38. }
  39. }
  40. }