add readable password generation

This commit is contained in:
o-psi
2023-12-18 17:34:59 +00:00
parent f0567c1fb7
commit ebaa2a084a
2 changed files with 143 additions and 93 deletions

View File

@@ -247,6 +247,30 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<!-- JavaScript to Show/Hide Password Form Group --> <!-- JavaScript to Show/Hide Password Form Group -->
<script> <script>
function generatePassword(type, id) {
var url = '/ajax.php?get_readable_pass=true';
// Make an AJAX request to the server
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var password = xhr.responseText;
// Set the password value based on the type
if (type == "add") {
document.getElementById("password-add").value = password;
} else if (type == "edit") {
console.log("password-edit-"+id.toString());
document.getElementById("password-edit-"+id.toString()).value = password;
}
}
};
xhr.send();
}
$(document).ready(function() { $(document).ready(function() {
$('.authMethod').on('change', function() { $('.authMethod').on('change', function() {
var $form = $(this).closest('.authForm'); var $form = $(this).closest('.authForm');
@@ -257,6 +281,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
} }
}); });
$('.authMethod').trigger('change'); $('.authMethod').trigger('change');
}); });
</script> </script>

View File

@@ -50,7 +50,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<div class="col-md-4"> <div class="col-md-4">
<div class="input-group mb-3 mb-md-0"> <div class="input-group mb-3 mb-md-0">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(nullable_htmlentities($q)); } ?>" placeholder="Search Logins"> <input type="search" class="form-control" name="q" value="<?php if (isset($q)) {
echo stripslashes(nullable_htmlentities($q));
} ?>" placeholder="Search Logins">
<div class="input-group-append"> <div class="input-group-append">
<button class="btn btn-dark"><i class="fa fa-search"></i></button> <button class="btn btn-dark"><i class="fa fa-search"></i></button>
</div> </div>
@@ -67,7 +69,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<hr> <hr>
<div class="table-responsive-sm"> <div class="table-responsive-sm">
<table class="table table-striped table-borderless table-hover"> <table class="table table-striped table-borderless table-hover">
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>"> <thead class="text-dark <?php if ($num_rows[0] == 0) {
echo "d-none";
} ?>">
<tr> <tr>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=login_name&order=<?php echo $disp; ?>">Name</a></th> <th><a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=login_name&order=<?php echo $disp; ?>">Name</a></th>
<th><a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=login_description&order=<?php echo $disp; ?>">Description</a></th> <th><a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=login_description&order=<?php echo $disp; ?>">Description</a></th>
@@ -118,7 +122,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$login_software_id = intval($row['login_software_id']); $login_software_id = intval($row['login_software_id']);
?> ?>
<tr class="<?php if(!empty($login_important)) { echo "text-bold"; }?>"> <tr class="<?php if (!empty($login_important)) {
echo "text-bold";
} ?>">
<td> <td>
<i class="fa fa-fw fa-key text-secondary"></i> <i class="fa fa-fw fa-key text-secondary"></i>
<a class="text-dark" href="#" data-toggle="modal" data-target="#editLoginModal<?php echo $login_id; ?>"> <a class="text-dark" href="#" data-toggle="modal" data-target="#editLoginModal<?php echo $login_id; ?>">
@@ -158,7 +164,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<?php <?php
require "client_login_edit_modal.php"; require "client_login_edit_modal.php";
} }
?> ?>
@@ -176,8 +181,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
function showOTP(id, secret) { function showOTP(id, secret) {
//Send a GET request to ajax.php as ajax.php?get_totp_token=true&totp_secret=SECRET //Send a GET request to ajax.php as ajax.php?get_totp_token=true&totp_secret=SECRET
jQuery.get( jQuery.get(
"ajax.php", "ajax.php", {
{get_totp_token: 'true', totp_secret: secret}, get_totp_token: 'true',
totp_secret: secret
},
function(data) { function(data) {
//If we get a response from post.php, parse it as JSON //If we get a response from post.php, parse it as JSON
const token = JSON.parse(data); const token = JSON.parse(data);
@@ -191,8 +198,10 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
function showOTPViaLoginID(login_id) { function showOTPViaLoginID(login_id) {
// Send a GET request to ajax.php as ajax.php?get_totp_token_via_id=true&login_id=ID // Send a GET request to ajax.php as ajax.php?get_totp_token_via_id=true&login_id=ID
jQuery.get( jQuery.get(
"ajax.php", "ajax.php", {
{get_totp_token_via_id: 'true', login_id: login_id}, get_totp_token_via_id: 'true',
login_id: login_id
},
function(data) { function(data) {
//If we get a response from post.php, parse it as JSON //If we get a response from post.php, parse it as JSON
const token = JSON.parse(data); const token = JSON.parse(data);
@@ -204,7 +213,24 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
} }
function generatePassword() { function generatePassword() {
document.getElementById("password").value = "<?php echo randomString(); ?>" document.getElementById("password").value = "<?php echo generateReadablePassword(3); ?>"
}
function generatePassword() {
var url = '/ajax.php?get_readable_pass=true';
// Make an AJAX request to the server
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
var password = xhr.responseText;
document.getElementById("password").value = password;
}
};
xhr.send();
} }
</script> </script>
@@ -219,4 +245,3 @@ require_once "client_login_import_modal.php";
require_once "client_login_export_modal.php"; require_once "client_login_export_modal.php";
require_once "footer.php"; require_once "footer.php";