Skip to content

Can I generate a 2FA code at the command line? #956

Discussion options

You must be logged in to vote

Here is an example file totp.php. It's a minimal TOTP token generator in a few lines of PHP. No special libraries required, only PHP must be installed on your system. Unfortunately I couldn't find a Base32 decode in the built-in PHP functions, so this was the shortest solution I came up with. You can configure your secret keys in the file. The required parameters are a label and a secret key.

<?php
// TOTP token generator for the command line, https://github.com/datenstrom
// This will generate a 6 digit code used for two-factor authentication (2FA).
// A token is only valid for 30 seconds, then a new one must be generated.
    
const VERSION = "0.8.15";
    
// Configure secret keys, for…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by annaesvensson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants