pyauth / pyotp

Python One-Time Password Library
https://pyauth.github.io/pyotp/
Other
2.91k stars 319 forks source link

Basic terminal-console functionallity #159

Open GiorgosXou opened 4 months ago

GiorgosXou commented 4 months ago

This might be handy for some people... eg. today i had to use your library for pip two-factor authentication... But feel free to change anything or even drop this pull-request if you think otherwise.

>  pyotp --help
usage: pyotp [-h] [--hotp NUMBER] [--hex] [-v] [secret]

positional arguments:
  secret         base32 secret

options:
  -h, --help     show this help message and exit
  --hotp NUMBER  specify HOTP position\number
  --hex          returns a 40-character hex-encoded secret
  -v, --version  show program's version number and exit

Generate a 32-character base32 secret:

> pyotp
BQ5NYTKAEIDXVF24W5HM2BK7K2TTBEKE

... hex-encoded:

> pyotp --hex
FD5FF5943E44373F4062773365EE865C5196D56B

Get TOTP digits:

> pyotp BQ5NYTKAEIDXVF24W5HM2BK7K2TTBEKE
378127

Get HOTP digits

> pyotp BQ5NYTKAEIDXVF24W5HM2BK7K2TTBEKE --hotp 0
398346

peace and love

peterthomassen commented 4 months ago

Secret should be read from stdin (not passed as an argument) as it can otherwise be observed by other users on the same machine (by inspecting the process list).

GiorgosXou commented 4 months ago

@peterthomassen how about:

> pyotp -h
PyOTP v.2.9.0 usage:
  pyotp  - Generate a 32-character base32 secret
  pyotph - Generate a  hex-encoded base32 secret
  pytotp - Return TOTP digits from base32 secret
  pyhotp - Return HOTP digits from base32 secret
> pyotp
C5B7WOU3VTI6CHGQZCYQX7VPFT2W257E
> pyotph
74524F37F12534CA383162CBB56A433776CAC65B
> pytotp
Enter base32 secret: C5B7WOU3VTI6CHGQZCYQX7VPFT2W257E
983511
> pyhotp
Enter base32 secret: C5B7WOU3VTI6CHGQZCYQX7VPFT2W257E
Enter number: 23
983754

Simple, yet intuitive.

peterthomassen commented 4 months ago

Another option would be to allow passing the secret in a file, and allow the filename to be /dev/stdin (or - for short).