Skip to content

Instantly share code, notes, and snippets.

@cstayyab
Last active February 16, 2023 00:49
Show Gist options
  • Save cstayyab/d26b71ab66783ab7462c0489d885fa9e to your computer and use it in GitHub Desktop.
Save cstayyab/d26b71ab66783ab7462c0489d885fa9e to your computer and use it in GitHub Desktop.
A Bookmarklet to quickly generate a random string of desired length

Create a bookmark with following link in you browser's bookmarks bar to have one click password (or alpha-numeric string) generator:

javascript:(() => { 
  prompt('Please copy the following generated String', (
    function generateRandomString(length) {  
      const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';  
      let result = '';  
      for (let i = 0; i < length; i++) {    
        const randomIndex = Math.floor(Math.random() * chars.length);    
        result += chars.charAt(randomIndex);  
      }  
      return result;
    })(window.prompt('Enter the desired length of string:', 16))); return false;})()
@cstayyab
Copy link
Author

Need help?

Here are the steps to Create a Bookmarklet in Chrome (Other browsers have similar process):

  1. Right Click the Bookmarks Bar and Select "Add Page"

Context Menu of Google Chrome's Bookmarks Bar

  1. Paste the above Code in the "URL" field and type a suitable name (e.g. "Generate Password") in the Name Field.

image

  1. Make Sure "Bookmarks Bar" Folder is selected in the List and Click "Save"

  2. Click your newly created bookmark from the Bookmarks Bar to test it out.

  3. Don't keep it just to yourself, share it with others too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment