Skip to content

jack456054/selenium-google-authenticator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

selenium-google-authenticator

Description

This is a simple Python script that uses Selenium + pyotp to automate the process of logging into a Google account with Google Authenticator enabled. It is useful for people who have multiple Google accounts and want to automate the process of logging into their Google accounts.

Installation

Install Poetry (https://python-poetry.org/docs/#installation) and run poetry install in the root directory of the project.

$ brew install poetry

Install Python(3.11.4) dependencies

$ poetry install

Setup environment variables

Create a .env file in the root directory of the project and add the following variables:

email=[Your Google Account Email]
password=[Your Google Account Password]
otp_secret=[Your Google Authenticator Secret] # This can be found in the Google Authenticator app, which we will show you how to do later.

Setup Google Authenticator

Login to your Google Account and go to the Google Authenticator page. Click on the Set up button and follow the instructions to set up Google Authenticator. Once you have set up Google Authenticator, you will be able to see your secret key. Copy the secret key and paste it into the otp_secret variable in the .env file.

Alt text Alt text Alt text Alt text Alt text

You can find you OTP secret key like:

xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx

Fill in the opt_secret variable in the .env file with the secret key(without withespaces), which should look like this:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Run the program

$ poetry run python main.py

Google Account 2FA

Google Account uses TOTP to generate one-time passwords. The secret key is stored on the server and the verification code is generated by the client. The verification code is valid for 30 seconds. The client and server must be synchronized to ensure that the verification code is valid.

Time-based One-time Password Algorithm(TOTP)

The Time-based One-time Password Algorithm(TOTP) is an algorithm that computes a one-time password from a shared secret key and the current time. It has been adopted as Internet Engineering Task Force standard RFC 6238, is the cornerstone of Initiative For Open Authentication (OATH), and is used in a number of two-factor authentication systems(2FA). You can find shared secret key while you're setting up Google Account 2FA. current time is the time on your computer in seconds since the Unix epoch, divided by the number of seconds in the time step. The time step is usually 30 seconds. Then, hash the shared secret key with the HMAC algorithm using the SHA-1 hash function. This will produce a 20-byte digest. Then, use dynamic truncation to extract a 4-byte(32-bit) code from the digest. This is the one-time password. Finally, compute the one-time password as a 6-digit decimal integer. This will be the one-time password that you will use to log into your Google account. You can find more information about TOTP here.

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages