ike Posted July 2, 2009 Share Posted July 2, 2009 I thought it would be useful to have a quick "generate random password" button on a few admin pages. I couldn't find editable template files for the admin pages (other than a few of the basic .tpl files), so I decided to implement it with Javascript. Basically, the JS looks for password input boxes, and then adds a "Generate" button after them. This should be considered experimental as I just wrote it tonight, but it seems to be working very well in my tests. Here's what it looks like: Here's what you do: Create a new file, /whmcs_path/admin/autoPassword.js Content: // AddAutoPasswordButtons: Look for password boxes and add a generate password button next to tehm function AddAutoPasswordButtons() { // Don't add the Generate button to certain pages where it wouldn't make sense var NoGenerate = [ 'WHMCS - Servers', 'WHMCS - Support Ticket Departments' ]; for (i=0; i<NoGenerate.length; i++) if (document.title == NoGenerate[i]) return; // Get the Password text box, if there is one var e = document.getElementsByName("password"); if (e.length>0) { var b = document.createElement("input"); b.type = "button"; b.value = "Generate"; b.onclick = GeneratePassword; e[0].parentNode.appendChild(b); } } // GeneratePassword: Generate a password and place it in a textbox function GeneratePassword() { var p = GetRandomPassword(); var e = document.getElementsByName("password"); if (e.length>0) { e[0].value = p; if (e[0].type == "password") e[0].type = "text"; } // For a "confirm password" field e = document.getElementsByName("password2"); if (e.length>0) { e[0].value = p; if (e[0].type == "password") e[0].type = "text"; } } // GetRandomNumber: Get a random number between two specified numbers function GetRandomNumber(lbound,ubound) { return (Math.floor(Math.random() * (ubound-lbound)) + lbound); } // GetRandomCharacter: Get a random character function GetRandomCharacter() { var chars = ""; // Choose your character sets below chars += "0123456789"; chars += "abcdefghijklmnopqrstuvwxyz"; chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; return chars.charAt(GetRandomNumber(0,chars.length)); } // GetRandomPassword: Get a random password function GetRandomPassword() { var p = ""; for (i=0; i<8; i++) p += GetRandomCharacter(); return p; } //------------------------------------------------------------------------------ // Adding events to onLoad // Source: http://onlinetools.org/articles/unobtrusivejavascript/chapter4.html function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, false); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } // Hook AddAutoPasswordButtons to window load addEvent(window,'load',AddAutoPasswordButtons); Then, we just need to edit /whmcs_path/admin/templates/v4/header.tpl to reference the new .js file. I added the following on line 39 just before </head>: <script type="text/javascript" src="autoPassword.js"></script> This is what it looks like in context: });{/literal} {$jscode} </script> [b]<script type="text/javascript" src="autoPassword.js"></script>[/b] </head> <body> <div id="topnav"> That's it! Let me know if you find this useful or see any problems. I'll update this thread if I make any changes. 0 Quote Link to comment Share on other sites More sharing options...
Roger Posted July 2, 2009 Share Posted July 2, 2009 Hey pretty cool.... it works just fine for me. Thank you for the mod 0 Quote Link to comment Share on other sites More sharing options...
rodeoXtreme Posted July 2, 2009 Share Posted July 2, 2009 Nice Ike! Thank you 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Support Manager WHMCS John Posted July 2, 2009 WHMCS Support Manager Share Posted July 2, 2009 Cool. Don't forget to add it to the community contributions system in the client area! 0 Quote Link to comment Share on other sites More sharing options...
Business Hosting Online Posted July 2, 2009 Share Posted July 2, 2009 A nice tweak to this, would be to add it to the client registration form also on checkout, could this be done? 0 Quote Link to comment Share on other sites More sharing options...
uberhost Posted July 2, 2009 Share Posted July 2, 2009 Well done, Ike. 0 Quote Link to comment Share on other sites More sharing options...
ike Posted July 3, 2009 Author Share Posted July 3, 2009 A nice tweak to this, would be to add it to the client registration form also on checkout, could this be done? Good idea. The current version can't be implemented as-is on the customer portal for a couple reasons but it will definitely be possible with a few changes. Cool. Don't forget to add it to the community contributions system in the client area! I should have a new version later tonight or tomorrow. I'll post an update here and submit it to the community contributions when it's ready. 0 Quote Link to comment Share on other sites More sharing options...
ipglobe Posted July 3, 2009 Share Posted July 3, 2009 In Administrators ocorred one error Detalhes dos erros da página da Web Agente de Usuário: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729) Carimbo de data/hora: Fri, 3 Jul 2009 18:05:48 UTC Mensagem: Unable to get the property type. There is no support for this command. Linha: 28 Caractere: 32 Código: 0 URI: https://www.xxx.net/xxx/admin/autoPassword.js Mensagem: Unable to get the property type. There is no support for this command. Linha: 28 Caractere: 32 Código: 0 URI: https://www.xxx.net/xxx/admin/autoPassword.js Mensagem: Unable to get the property type. There is no support for this command. Linha: 28 Caractere: 32 Código: 0 URI: https://www.xxx.net/xxx/admin/autoPassword.js Please help!!! 0 Quote Link to comment Share on other sites More sharing options...
ike Posted July 4, 2009 Author Share Posted July 4, 2009 Hi everyone, I have just submitted the addon to the community contributions system and it is awaiting approval. In the mean time, you can download the new version of the addon here: http://ike.to/whmcs_addons/password_generator/pwgen_1.0.zip Note that I changed the Javascript file's name and location for consistency. Also, the header.tpl modification in the admin area has changed slightly. Full installation instructions are included in the zip file. Other changes: Added client-side integration instructions for the checkout page Fixed the IE bug mentioned by ipglobe Changed the "Generate" button placement so it will always be next to the password field 0 Quote Link to comment Share on other sites More sharing options...
Business Hosting Online Posted July 4, 2009 Share Posted July 4, 2009 Whooohooooo off to install. 0 Quote Link to comment Share on other sites More sharing options...
jmanuel Posted July 5, 2009 Share Posted July 5, 2009 Greats!!! Thanks!! 0 Quote Link to comment Share on other sites More sharing options...
Seb Posted July 6, 2009 Share Posted July 6, 2009 Handy addition - thanks. Stops all the passwords changes I make for people being obviously repetitive keystrokes! (e.g. lkjlkjlkjlkjlkjlkj) 0 Quote Link to comment Share on other sites More sharing options...
UNIXIELHOST Posted July 6, 2009 Share Posted July 6, 2009 I am using default cart and I tried to add, it came error. Cuz the example file are for v4, I am using default themes... 0 Quote Link to comment Share on other sites More sharing options...
crazyfish Posted July 6, 2009 Share Posted July 6, 2009 Very handy. Thanks! 0 Quote Link to comment Share on other sites More sharing options...
ike Posted July 6, 2009 Author Share Posted July 6, 2009 I am using default cart and I tried to add, it came error. Cuz the example file are for v4, I am using default themes... Did you copy my file for the "cart" orderform into your "default" orderform? If so, that would cause a problem. I didn't make examples for the other carts provided by the system, I could though if you want. Upload a copy of the file you modified and I'll take a look. 0 Quote Link to comment Share on other sites More sharing options...
ike Posted July 7, 2009 Author Share Posted July 7, 2009 Actually, it just occurred to me that I think you meant you're using the "default" client-side theme as opposed to the "portal" theme. In that case, just edit the /templates/default/header.tpl file the same way you would edit the /templates/portal/header.tpl file. 0 Quote Link to comment Share on other sites More sharing options...
ipglobe Posted July 14, 2009 Share Posted July 14, 2009 Very, very goooooood. Thank youuuu 0 Quote Link to comment Share on other sites More sharing options...
dkent Posted July 20, 2009 Share Posted July 20, 2009 Extremely easy to set up! Took me less than 5 minutes Very nice feature - thanks! 0 Quote Link to comment Share on other sites More sharing options...
EasyWHMCS Posted July 20, 2009 Share Posted July 20, 2009 Very nice addon, thank you 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted August 1, 2009 Share Posted August 1, 2009 Hi I have just installed this and it is only putting the P/W in the Confirm Password box within the cart.php?a=checkout and not in both Password box and the Confirm Password box that it is needed on both 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted August 1, 2009 Share Posted August 1, 2009 also it look like it is not useing the dot's/stars the it was before? that is in FF 0 Quote Link to comment Share on other sites More sharing options...
MikeP Posted August 11, 2009 Share Posted August 11, 2009 Will this work on the client side? 0 Quote Link to comment Share on other sites More sharing options...
edvan.com.br Posted August 13, 2009 Share Posted August 13, 2009 Suggestions Include: password_generator.js ( see attach file: clientareachangepw.tpl.jpg ) // compatibility for the template clientareachangepw.tpl function GeneratePassword2() { var p = GetRandomPassword(); var e = document.getElementsByName("newpw"); if (e.length>0) { e[0].value = p; if (e[0].type == "password") changeInputType(e[0],"text"); } // For a "confirm password" field e = document.getElementsByName("confirmpw"); if (e.length>0) { e[0].value = p; if (e[0].type == "password") changeInputType(e[0],"text"); } } in clientareachangepw.tpl <input type="button" value="Gerar Senha" onclick="GeneratePassword2();"/> Another suggestion: /clientregister.tpl ( see attach file: clientregister.tpl.jpg ) Congratulations 0 Quote Link to comment Share on other sites More sharing options...
EhsanCh Posted January 5, 2010 Share Posted January 5, 2010 im using pwgen addon for firefox 0 Quote Link to comment Share on other sites More sharing options...
EasyWHMCS Posted January 5, 2010 Share Posted January 5, 2010 im using pwgen addon for firefox Thats a addon for firefox not whmcs 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.