mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 13:24:01 -07:00
refactor: Password generation (#1847)
* refactor: Password generation * Update main.js * Update usercp_register.tpl * Update main.js * Updated * Update main.js
This commit is contained in:
parent
bd0ef063fa
commit
af2403f191
2 changed files with 27 additions and 13 deletions
|
@ -460,19 +460,33 @@ $(document).ready(function () {
|
||||||
/**
|
/**
|
||||||
* Autocomplete password
|
* Autocomplete password
|
||||||
**/
|
**/
|
||||||
var array_for_rand_pass = ["a", "A", "b", "B", "c", "C", "d", "D", "e", "E", "f", "F", "g", "G", "h", "H", "i", "I", "j", "J", "k", "K", "l", "L", "m", "M", "n", "N", "o", "O", "p", "P", "q", "Q", "r", "R", "s", "S", "t", "T", "u", "U", "v", "V", "w", "W", "x", "X", "y", "Y", "z", "Z", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
function generatePassword(length) {
|
||||||
var array_rand = function (array) {
|
const lowercaseChars = "abcdefghijklmnopqrstuvwxyz";
|
||||||
var array_length = array.length;
|
const uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
var result = Math.random() * array_length;
|
const numberChars = "0123456789";
|
||||||
return Math.floor(result);
|
const specialChars = "!@#$%^&*()_+~`|}{[]:;?><,./-=";
|
||||||
};
|
|
||||||
|
|
||||||
var autocomplete = function (noCenter) {
|
let password = [
|
||||||
var string_result = ""; // Empty string
|
getRandomChar(lowercaseChars),
|
||||||
for (var i = 1; i <= 8; i++) {
|
getRandomChar(uppercaseChars),
|
||||||
string_result += array_for_rand_pass[array_rand(array_for_rand_pass)];
|
getRandomChar(numberChars),
|
||||||
|
getRandomChar(specialChars)
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 4; i < length; i++) {
|
||||||
|
password.push(getRandomChar(lowercaseChars));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
password = password.sort(() => Math.random() - 0.5);
|
||||||
|
return password.slice(0, length).join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomChar(charSet) {
|
||||||
|
return charSet[Math.floor(Math.random() * charSet.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
var autocomplete = function (noCenter = false, passwordLength = 10) {
|
||||||
|
let string_result = generatePassword(passwordLength);
|
||||||
var _popup_left = (Math.ceil(window.screen.availWidth / 2) - 150);
|
var _popup_left = (Math.ceil(window.screen.availWidth / 2) - 150);
|
||||||
var _popup_top = (Math.ceil(window.screen.availHeight / 2) - 50);
|
var _popup_top = (Math.ceil(window.screen.availHeight / 2) - 50);
|
||||||
|
|
||||||
|
@ -491,7 +505,7 @@ var autocomplete = function (noCenter) {
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("span#autocomplete").click(function () {
|
$("span#autocomplete").click(function () {
|
||||||
autocomplete();
|
autocomplete(false, $(this).data('password-length'));
|
||||||
});
|
});
|
||||||
|
|
||||||
var _X, _Y;
|
var _X, _Y;
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<div class="title">{L_YOUR_NEW_PASSWORD}</div>
|
<div class="title">{L_YOUR_NEW_PASSWORD}</div>
|
||||||
<div>
|
<div>
|
||||||
<input value="" autocomplete="off" type="text"/>
|
<input value="" autocomplete="off" type="text"/>
|
||||||
<span class="regenerate" title="{L_REGENERATE}" onclick="autocomplete(true);"></span>
|
<span class="regenerate" title="{L_REGENERATE}" onclick="autocomplete(true, {#PASSWORD_MIN_LENGTH#});"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="prof-title"><!-- IF EDIT_PROFILE -->{L_NEW_PASSWORD}: * <br/><h6>{L_PASSWORD_IF_CHANGED}</h6><!-- ELSE -->{L_PASSWORD}: *<!-- ENDIF --></td>
|
<td class="prof-title"><!-- IF EDIT_PROFILE -->{L_NEW_PASSWORD}: * <br/><h6>{L_PASSWORD_IF_CHANGED}</h6><!-- ELSE -->{L_PASSWORD}: *<!-- ENDIF --></td>
|
||||||
<td>
|
<td>
|
||||||
<input id="pass" type="<!-- IF SHOW_PASS -->text<!-- ELSE -->password<!-- ENDIF -->" name="new_pass" size="35" maxlength="32" value=""/> <span id="autocomplete" title="{L_AUTOCOMPLETE}">◄</span> <i class="med">{PASSWORD_LONG}</i>
|
<input id="pass" type="<!-- IF SHOW_PASS -->text<!-- ELSE -->password<!-- ENDIF -->" name="new_pass" size="35" maxlength="32" value=""/> <span id="autocomplete" data-password-length="{#PASSWORD_MIN_LENGTH#}" title="{L_AUTOCOMPLETE}">◄</span> <i class="med">{PASSWORD_LONG}</i>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue