Random Password Generator

Generate secure random password

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Random Password Generator
// @namespace    https://openuserjs.org/users/burn
// @version      20260207
// @description  Generate secure random password
// @copyright    2026, burn (https://openuserjs.org//users/burn)
// @license      MIT
// @match        *://*/*
// @include      *
// @grant        GM_registerMenuCommand
// @grant        GM.registerMenuCommand
// @grant        GM_setClipboard
// @grant        GM.setClipboard
// ==/UserScript==

// ==OpenUserJS==
// @author burn
// ==/OpenUserJS==

/*jshint esversion: 8 */ 
(function() {
    'use strict';
    const DBG = false;
    const SCRIPT = GM_info.script.name;
    let log = (str) => {
        DBG && console.log(GM_info.script.name + " | " + str);
    };

    function secureRandomIndex(max) {
        const range = 0xFFFFFFFF;
        const limit = range - (range % max);
        const buf = new Uint32Array(1);

        do {
            crypto.getRandomValues(buf);
        } while (buf[0] >= limit);

        return buf[0] % max;
    }

    function pick(str) {
        return str[secureRandomIndex(str.length)];
    }

    Object.defineProperty(Array.prototype, "shuffle", {
        value: function() {
            for (let i = this.length - 1; i > 0; i--) {
                const j = secureRandomIndex(i + 1);
                [this[i], this[j]] = [this[j], this[i]];
            }
            return this;
        },
        enumerable: false
    });

    function generatePassword() {
        const LEN = 19;
        const LOWER = "abcdefghijkmnopqrstuvwxyz";
        const UPPER = "ABCDEFGHJKLMNPQRSTUVWXYZ";
        const NUM = "23456789";
        const SYM = "!@#$%^&*()-_=+[]{};:,.<>?";

        const ALL = LOWER + UPPER + NUM + SYM;

        const result = new Array(
            pick(LOWER),
            pick(UPPER),
            pick(NUM),
            pick(SYM)
        );

        for (let i = result.length; i < LEN; i++) {
            result.push(pick(ALL));
            result.shuffle();
        }

        if (typeof GM_setClipboard !== "undefined") {
            GM_setClipboard(result.join(""), "text");
        } else if (typeof GM !== "undefined" && GM.setClipboard) {
            GM.setClipboard(result.join(""), "text");
        }
    }

    if (typeof GM_registerMenuCommand !== "undefined") {
        GM_registerMenuCommand("Generate Secure Password", generatePassword);
    } else if (typeof GM !== "undefined" && GM.registerMenuCommand) {
        GM.registerMenuCommand("Generate Secure Password", generatePassword);
    }
})();