I have a password generator for registrations on the site, I want to convert it into a link generator for my site, so that when I click on "generate", I open a new page and display a link with the generated address of the form: http://*****.ру/ (generator value)

 <SCRIPT language="JavaScript" SRC="1.js"></SCRIPT> <center> <table width=80% border=0> <tr align=center> <td> <form name="myform"> <table border=0> <tr> <td bgcolor="#B7DADB"> 1-й элемент может быть: </td> <td bgcolor="#B7DADB"> <input type=checkbox name=firstNumber checked>Цифра <input type=checkbox name=firstLower checked>Прописная <input type=checkbox name=firstUpper checked>Заглавная <input type=checkbox name=firstOther>Другие элементы </td> </tr> <tr> <td bgcolor="#D4D4D4"> Последующие элементы: </td> <td bgcolor="#D4D4D4"> <input type=checkbox name=latterNumber checked>Цифра <input type=checkbox name=latterLower checked>Прописная <input type=checkbox name=latterUpper checked>Заглавная <input type=checkbox name=latterOther>Другие элементы </td> </tr> <tr> <td bgcolor="#999999"> Длина пароля: </td> <td bgcolor="#999999"> <input type=text name=passwordLength value="8" size=3> </td> </tr> <tr> <td bgcolor="#999999"> Доп. элементы: </td> <td bgcolor="#999999"> <input type=text name=extraChars size=20> </td> </tr> </font> <tr> <td bgcolor="#999999"> <font size="4" color="#FFFFFF">Новый пароль: </font> </td> <font size="4" color="#FF0000"> <td bgcolor="#999999"> <font size="4" color="#FF0000"> <input type=text name=password size=20> </font> </td> </tr> <tr> <td bgcolor="#999999"> &nbsp; </td> <td bgcolor="#999999"> <font size="4" color="#FF0000"><input type=button value="Сгенерировать пароль" onClick="document.myform.password.value = getPassword(document.myform.passwordLength.value, document.myform.extraChars.value, document.myform.firstNumber.checked, document.myform.firstLower.checked, document.myform.firstUpper.checked, document.myform.firstOther.checked, document.myform.latterNumber.checked, document.myform.latterLower.checked, document.myform.latterUpper.checked, document.myform.latterOther.checked);" style="font-size: 8pt; font-family: Arial"> &nbsp; </font> </td> </tr> </table> </td> </tr> </table> </center> 

1.js

 function getRandomNum(lbound, ubound) { return (Math.floor(Math.random() * (ubound - lbound)) + lbound); } function getRandomChar(number, lower, upper, other, extra) { var numberChars = "0123456789"; var lowerChars = "abcdefghijklmnopqrstuvwxyz"; var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var otherChars = "`~!@#$%^&*()-_=+***91;{***93;}\\|;:'\",<.>/? "; var charSet = extra; if (number == true) charSet += numberChars; if (lower == true) charSet += lowerChars; if (upper == true) charSet += upperChars; if (other == true) charSet += otherChars; return charSet.charAt(getRandomNum(0, charSet.length)); } function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther, latterNumber, latterLower, latterUpper, latterOther) { var rc = ""; if (length > 0) rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars); for (var idx = 1; idx < length; ++idx) { rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars); } return rc; } 

All that is needed from the code is that it opens a new page and displays a page with the value of the generator. Thank you in advance.

  • And the purpose of all this fraud please tell me? - pelmeshka80
  • one
    Do you want to generate an address like http://i32^dF{.ru ? Can you explain more intelligibly? - ling
  • no, I want to make my website. / i32 ^ dF { - cy_r_ax

1 answer 1

 function getRandomNum(lbound, ubound) { return (Math.floor(Math.random() * (ubound - lbound)) + lbound); } function getRandomChar(number, lower, upper, other, extra) { var numberChars = "0123456789"; var lowerChars = "abcdefghijklmnopqrstuvwxyz"; var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var otherChars = "`~!@#$%^&*()-_=+***91;{***93;}\\|;:'\",<.>/? "; var charSet = extra; if (number == true) charSet += numberChars; if (lower == true) charSet += lowerChars; if (upper == true) charSet += upperChars; if (other == true) charSet += otherChars; return charSet.charAt(getRandomNum(0, charSet.length)); } function openRandPage() { var url = 'http://мой сайт.ру/'; for(var i=0;i<10;i++){url+=getRandomChar(true, true, true, true, true)} window.open(url, 'newWindow') } openRandPage(); // запуск функции, можно повесить на онклик 
  • That is, now, when inserting this code changed to the url /, the value getRandomChar (generator value) will be added? - cy_r_ax
  • I did not check the performance of the code. The main point is to form a random abracadabra. The getrandomChar function, which uses getRandomNum, does a great job with this. One character to add to url and open in a new window. PS code works. One typo was now fixed - Enpire
  • It works great, but at the end does not attribute the value after the url / *** address - cy_r_ax
  • It works, everything is just super! Thanks for the help. ) - cy_r_ax
  • var charSet = extra; - maybe var charSet = ''; ? - ling