<h1 id="norrist-uses-a-raspberry-pi-pico-to-type-passwords">norrist uses
a raspberry pi pico to type passwords</h1>
<h2 id="password-managers">Password Managers</h2>
<ul>
<li>I like using a password managers</li>
<li>Every site has a different complex password</li>
<li>I use the browser plugin or copy paste.</li>
<li>I recently switched from last pass to bit warden.
<ul>
<li>I was one of the users that did not get prompted to increase the
number of password iterations from 1000.</li>
</ul></li>
<li>They work basically the same.</li>
</ul>
<h2 id="my-stupid-bank">My stupid bank</h2>
<ul>
<li>The normal procedure for changing passwords is
<ul>
<li>fill in old password</li>
<li>generate new random password</li>
<li>copy paste new password into the new password field</li>
</ul></li>
<li>For some reason, my bank's site uses JavaScript to block paste into
the new password fields</li>
<li>I don't know why banks or anyone disable pasting into a browser
field</li>
<li>The only way I could change my password, was to generate a password
simple enough that it could be manually typed into the change
fields</li>
</ul>
<h2 id="first-solution">First solution</h2>
<ul>
<li>I wanted to find something like a programmable keyboard where you
could input an input string and have the device type out the
characters</li>
<li>I found a few keyboards that used macros, but they seemed too simple
to use for a complex password.</li>
<li>I saw somewhere online that you could use a micro-controller to
emulate a keyboard.</li>
<li>I had a circuit playground express that I wasn't using for
anything.</li>
<li>The circuit playground express has 2 built in buttons</li>
<li>I found a circuit python tutorial for emulating keystrokes and
modified it so it would emulate the keystrokes for a password.</li>
<li>Button A would output a password and button B would output a
different password.</li>
</ul>
<h2 id="problems">Problems</h2>
<ul>
<li>The passwords were stored as variables in the code</li>
<li>The circuit playground express has a lot of built in LED's and touch
pads. It was really being wasted to only use it as a keyboard emulation
device</li>
<li>I have another project I want to use the playground express for</li>
</ul>
<h2 id="next-solution">Next Solution</h2>
<ul>
<li>Raspberry Pi Pico - $4 micro controller</li>
<li>I was able to get circuit python to micro controller a keyboard on
the pi pico</li>
<li>Not many ways to get physically interact with board.</li>
<li>No buttons and only one LED.</li>
<li>I decided the best way was to have a count down timer</li>
<li>blink the led to indicate where the timer was in the countdown</li>
<li>output the keystrokes when the countdown timer reached zero</li>
</ul>
<h2 id="more-problems">More problems</h2>
<ul>
<li>Circuit python devices work by exposing a small file system when
plugged in via USB.</li>
<li>You can mount the file system and edit the code running on the micro
controller</li>
<li>Once the device is powered on, it starts emulating keystrokes every
time the countdown timer cycles</li>
<li>to keep the micro controller keystrokes from interfering with any
work you were doing I would have to mount the device and quickly comment
out part of the code so it would stop sending keystrokes</li>
<li>As a fix, I added a check to only send keystrokes if a file named
<code>send_keys</code> exists</li>
<li>Now, I can work on the code and only add the <code>send_keys</code>
file when I an ready.</li>
</ul>
<h2 id="storing-the-password">Storing the password</h2>
<ul>
<li>I didn't like that the password I want to send as keystrokes was
stored as a variable in the code.</li>
<li>I modified that python to read the password from a separate file
named pw.txt</li>
</ul>
<h2 id="setup-the-pi-pico">Setup the Pi Pico</h2>
<h3 id="install-circuit-python">Install circuit python</h3>
<ul>
<li><a
href="https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython"
class="uri">https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython</a></li>
</ul>
<h3 id="bundle">Bundle</h3>
<ul>
<li><code>https://github.com/adafruit/Adafruit_CircuitPython_Bundle</code>
-&gt; Releases</li>
<li>Download <code>adafruit-circuitpython-bundle-py-20231219.zip</code>
or current version.</li>
<li>Create a <code>lib</code> directory on the circuit python
drive.</li>
<li>Copy the directory <code>lib/adafruit_hid</code> from the zip to
<code>lib</code> on the circuit python drive.</li>
</ul>
<h3 id="code.py">Code.py</h3>
<ul>
<li>Circuit python execute <code>code.py</code></li>
<li>Copy the code to send the passwords to the file
<code>code.py</code></li>
</ul>
<h2 id="how-to-use">How to use</h2>
<ul>
<li>Plug in the pico to your PC and mount the drive</li>
<li>The LED will blink - 1 second on and 1 second off</li>
<li>Save the password you want to input as keystrokes in the file
<code>pw.txt</code></li>
<li>When you are ready for the pico to do the typing, create the file
<code>send_keys</code></li>
<li>The LED's will blink fast 5 times, then 4 times, ...</li>
<li>Wait for the LED flashes to count down.</li>
<li>The pico will send the keystrokes and restart the countdown.</li>
<li>Remove the file <code>send_keys</code> so stop the input.</li>
<li>Overwrite pw.txt to be extra secure.</li>
</ul>
<h2 id="adapted-from-ada-fruit-circuit-python-examples">Adapted from Ada
fruit circuit python examples</h2>
<ul>
<li><a
href="https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/LICENSE">MIT
Licensed</a></li>
<li><a
href="https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Introducing_CircuitPlaygroundExpress/CircuitPlaygroundExpress_HIDKeyboard/code.py">Keyboard
Example</a></li>
</ul>
<h2 id="code">Code</h2>
<p><a href="https://gitlab.com/norrist/pico_pw_paste">Gitlab
Repo</a></p>
<hr />
<pre class="py"><code>import os
import time

import board
import digitalio
import usb_hid

# https://github.com/adafruit/Adafruit_CircuitPython_Bundle
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

with open(&quot;pw.txt&quot;, &quot;r&quot;) as pw_file:
    pw = pw_file.read()

a_keys_pressed = [Keycode.A, pw]
control_key = Keycode.SHIFT

# The keyboard object!
time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)  # We&#39;re in the US :)

def blink_count(i, delay):
    for _ in range(i):
        led.value = True
        time.sleep(delay)
        led.value = False
        time.sleep(delay)
    time.sleep(1)

def countdown_and_send():
    for i in reversed(range(6)):
        print(i)
        blink_count(i, delay=0.2)
    print(f&quot;Sending {a_keys_pressed} as keystrokes&quot;)
    for key in a_keys_pressed:
        if isinstance(key, str):  # If it&#39;s a string...
            keyboard_layout.write(key)  # ...Print the string

while True:
    print(&quot;Hello, CircuitPython!&quot;)
    try:
        os.stat(&quot;send_keys&quot;)
        countdown_and_send()
    except OSError:
        blink_count(1, 1)
        print(&quot;touch send_keys to enable keypresses&quot;)</code></pre>
<h3 id="playground-express-version">Playground express version</h3>
<pre class="python"><code># SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT

&quot;&quot;&quot;CircuitPython Essentials HID Keyboard example&quot;&quot;&quot;
import time

import usb_hid
from adafruit_circuitplayground import cp
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode

a_keys_pressed = [Keycode.A, &quot;aaaabbbbccccdddd@@&quot;]
b_keys_pressed = [Keycode.A, &quot;eeeeffffgggghhhh@@&quot;]


control_key = Keycode.SHIFT

time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard)  # We&#39;re in the US :)


print(&quot;Waiting for key pin...&quot;)

while True:
    if cp.button_a:
        print(&quot;A&quot;)
        for key in a_keys_pressed:
            if isinstance(key, str):  # If it&#39;s a string...
                keyboard_layout.write(key)  # ...Print the string
    elif cp.button_b:
        print(&quot;B&quot;)
        for key in b_keys_pressed:
            if isinstance(key, str):  # If it&#39;s a string...
                keyboard_layout.write(key)  # ...Print the string

    time.sleep(0.1)</code></pre>
<h2 id="links">Links</h2>
<ul>
<li><a href="https://circuitpython.org/"
class="uri">https://circuitpython.org/</a></li>
<li><a
href="https://learn.adafruit.com/adafruit-circuit-playground-express/overview"
class="uri">https://learn.adafruit.com/adafruit-circuit-playground-express/overview</a></li>
<li><a href="https://www.raspberrypi.com/products/raspberry-pi-pico/"
class="uri">https://www.raspberrypi.com/products/raspberry-pi-pico/</a></li>
</ul>
