home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2006 January / PCA126_DVD.iso / internet / nsb-setup.exe / chrome / toolkit.jar / content / mozapps / autofill / ChildPasswordDialog.js < prev    next >
Encoding:
JavaScript  |  2005-02-07  |  3.3 KB  |  151 lines

  1. //TODO JVL: Dupe in masterpassword.js const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
  2. //TODO JVL: Dupe in masterpassword.js const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
  3.  
  4. var gpk11dbService = null;
  5. var gToken = null;
  6. var proceed;
  7.  
  8. /**
  9.  * Handle on load event
  10.  **/
  11. function ChildPassword_OnLoad()
  12. {
  13.     var dialogTitle = window.arguments[0];
  14.     var passwordLabel = window.arguments[1];
  15.     //dump("Dialog Title: " + dialogTitle + ", Password Label: " + passwordLabel + "\n");
  16.     
  17.     if (dialogTitle != "")
  18.         document.getElementById("SimplePasswordPrompt").setAttribute("title", dialogTitle);
  19.     if (passwordLabel != "")
  20.         document.getElementById("passwordLabel").value = passwordLabel;
  21. }
  22.  
  23. /**
  24.  * Handle Cancel event
  25.  **/
  26. function ChildPassword_OnCancel()
  27. {
  28.     proceed.result = "CANCEL";
  29. }
  30.  
  31. /**
  32.  * Handle on textbox change event
  33.  **/
  34. function ChildPassword_OnTextChange()
  35. {
  36.     if (proceed.errorMessage == "")
  37.         return;
  38.  
  39.     proceed.errorMessage = "";
  40.     document.getElementById("errorMessage").value = "";
  41. }
  42.  
  43. /**
  44.  * Handle on load event
  45.  **/
  46. function SimplePassword_OnLoad()
  47. {
  48.     ChildPassword_OnLoad();
  49.     document.getElementById("password").value = "";
  50.  
  51.     proceed = window.arguments[2];
  52.     if (proceed)
  53.         document.getElementById("errorMessage").value = proceed.errorMessage;
  54. }
  55.  
  56. /**
  57.  * Handle OK event for the Simple Password dialog
  58.  **/
  59. function SimplePassword_OnOK()
  60. {
  61.     if (IsMatchingMasterPassword(document.getElementById("password").value))
  62.     {    
  63.         proceed.result = "OK";
  64.         return true;
  65.     }
  66.     else
  67.     {
  68.         proceed.errorMessage = GetStringLocale("passwordError");
  69.         document.getElementById("errorMessage").value = proceed.errorMessage;
  70.         return false;
  71.     }
  72. }
  73.  
  74. /**
  75.  * Handle on load event
  76.  **/
  77. function ConfirmPassword_OnLoad()
  78. {
  79.     document.getElementById("oldPass").value = "";
  80.     document.getElementById("newPass").value = "";
  81.     document.getElementById("confirmPass").value = "";
  82.  
  83.     proceed = window.arguments[0];
  84.     if (proceed)
  85.     {
  86.         document.getElementById("errorMessage").value = proceed.errorMessage;
  87.         if (proceed.password.length <= 0)
  88.             document.getElementById("oldPass").setAttribute("disabled", true);
  89.     }
  90. }
  91.  
  92. /**
  93.  * Handle OK event for the Confirm Password dialog
  94.  **/
  95. function ConfirmPassword_OnOK()
  96. {
  97.     var password = document.getElementById("newPass").value;
  98.     if (proceed.password == document.getElementById("oldPass").value)
  99.     {
  100.         if (password == document.getElementById("confirmPass").value)
  101.         {
  102.             proceed.password = password;
  103.             proceed.result = "OK";
  104.         }
  105.         else
  106.         {
  107.             proceed.errorMessage = GetStringLocale("newPasswordError");
  108.         }
  109.     }
  110.     else
  111.     {
  112.         proceed.errorMessage = GetStringLocale("oldPasswordError");
  113.     }
  114.     window.close();
  115. }
  116.  
  117. /**
  118.  * Get the localized string
  119.  **/
  120. function GetStringLocale(val)
  121. {
  122.     if (val.length > 0)
  123.     {
  124.         var bundle = document.getElementById("formfillpasscardBundle");
  125.         if (bundle)
  126.             return bundle.getString(val);
  127.     }
  128.     return "";
  129. }
  130.  
  131. /**
  132.  * Check if the Master Password matches the given password
  133.  * Note: Duplicated from masterpassword.js
  134.  **/
  135. function IsMatchingMasterPassword(againstPassword)
  136. {
  137.         var tokenName = "";
  138.         
  139.         if (gpk11dbService == null)
  140.         {
  141.                 gpk11dbService = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
  142.                 if (gpk11dbService && gToken == null)
  143.                         gToken = gpk11dbService.findTokenByName(tokenName);
  144.         }
  145.         
  146.         if (gToken == null)
  147.                 return false;
  148.         
  149.         return gToken.checkPassword(againstPassword);
  150. }
  151.