2015年8月12日 星期三

.NET MVC - Active Directory Login 【AD登入驗證】Windows Server 2012 R2

  1. public ActionResult Login(string UserName, string Password, string returnUrl)
  2. {
  3. string user = UserName + domain;
  4.  
  5. //string pathStr = string.Format("LDAP://{0}{1}{2}", ip, port, baseDN);
  6.  
  7. try
  8. {
  9. DirectoryEntry de = new DirectoryEntry("LDAP://192.168.64.128:389/OU=MyMemberServers,DC=eSecure,DC=com", user, Password);
  10. Guid guid = de.Guid;
  11. //DirectorySearcher ds = new DirectorySearcher(de);
  12. de.Dispose();
  13. return View("ChangePassword");
  14. }
  15. catch (Exception)
  16. {
  17. PrincipalContext ctx = new PrincipalContext(ContextType.Domain, ip, inputBaseDN, admUser+domain, admPwd);
  18.  
  19. UserPrincipal userObj = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, UserName);
  20.  
  21.  
  22.  
  23. if (userObj != null)
  24. {
  25. //帳號停用,userObj.Enabled可能為null true false
  26. bool? isEnable = userObj.Enabled;
  27. //isEnable = null;
  28. if (!isEnable.HasValue)
  29. {
  30. ViewBag.Message = "系統發生錯誤,請聯絡系統管理員";
  31. }
  32. else if ((bool)!isEnable)
  33. {
  34. ViewBag.Message = "帳號已停用,請聯絡系統管理員";
  35. }
  36. else
  37. {
  38. bool isLockedOut = userObj.IsAccountLockedOut();
  39. if (isLockedOut)
  40. {
  41. ViewBag.Message = "帳號已被鎖定,請聯絡系統管理員";
  42. }
  43. else
  44. {
  45. Int32 badLogonCount = userObj.BadLogonCount;
  46. ViewBag.Message = "密碼錯誤" + badLogonCount + "次,錯誤3次帳號即被鎖定";
  47. }
  48. }
  49. return View("Login");
  50. }
  51. ctx.Dispose();
  52.  
  53. ViewBag.Message = "查無此帳號";
  54. return View("Login");
  55. }
  56. }

2015年7月30日 星期四

2015年7月15日 星期三

photoshop CS 6 Portable 疑難雜症

1.無法將圖片直接拖曳到ps編輯畫面內:


    開始 輸入 regedit HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion > Policies > System 找到EnableLUA 將1改成0,然後重啟電腦

2.變更語系: 中文 > 英文 


    ~\Adobe\Adobe Photoshop CS5\Locales\zh_TW\Support Files 找到tw10428.dat的檔案後,把它砍掉