Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Generate extremely secure random password (Unicode) with auto paste

Description
This macro will generate a random unicode string and paste it. Note that it does not put the result on the clipboard, so it must be run via hotkey.
Language
C#.net
Minimum Version
Created By
jackz98
Contributors
-
Date Created
Aug 21, 2019
Date Last Modified
Aug 21, 2019

Macro Code

using System;
using System.Text;
using System.Security.Cryptography;
// The 'text' parameter will contain the text from the:
//   - Current Clipboard when run by HotKey
//   - History Item when run from the History Menu
// The returned string will be:
//   - Placed directly on the Clipboard
//   - Ignored by ClipboardFusion if it is 'null'
public static class ClipboardFusionHelper
{
    static StringBuilder table = new StringBuilder(256);

    static ClipboardFusionHelper()
    {
        for (int i = 33; i <= 126; ++i)
        {
            table.Append((char)i);
        }
        for (char ch = '\u00AE'; ch < '\u00AE' + (256 - (126 - 33 + 1)); ++ch)
        {
            table.Append(ch);
        }
    }

    internal static string ToStr(byte[] byteArray)
    {
        string a = "";
        foreach(byte b in byteArray)
        {
            a += table[b];
        }
        return a;
    }

    public static string ProcessText(string text)
    {
        using (RandomNumberGenerator rng = new RNGCryptoServiceProvider())
        {
            byte[] rngData = new byte[20];
            rng.GetBytes(rngData);

            BFS.ClipboardFusion.PauseClipboardListener();

            BFS.Clipboard.PasteText(ToStr(rngData));
            BFS.Clipboard.Clear();

            BFS.ClipboardFusion.ResumeClipboardListener();
        }
        return null;
    }
}