Rishi Kashyap
Published © GPL3+

IoT based Login Alert System & Human/Bot Verification

Create a human/bot verification test using a push button and a login alert system using buzzer & email

IntermediateFull instructions provided1 hour549
IoT based Login Alert System & Human/Bot Verification

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Buzzer
Buzzer
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Male/Male Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×2
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Bolt IoT Bolt Python Library
Mailgun - Email API

Story

Read more

Schematics

Buzzer & Push button circuit

The push-button switch is pressed when asked by the prompt. The buzzer switches on as an alert

Code

Main code

Python
This code has the driver program along with logic for alert and push button check
import conf                        #Import conf file which holds the configurations details for Bolt,SMS & Email
import json,time                   #Import json & time libraries
from boltiot import Bolt,Email #Import Sms,Bolt,Email to create instances to send sms,emails or interact with bolt module



mybolt=Bolt(conf.API_KEY,conf.DEVICE_ID)        #Create a Bolt instance using device ID and API key

mailer = Email(conf.MAILGUN_API_KEY,conf.SANDBOX_URL,conf.SENDER_EMAIL,conf.RECIPIENT_EMAIL)  #Create an Email instance using API,Domain,Sender and Receiver E-mail

#Function which checks if the user has pressed the push-button switch
def button_check():
    print("Press and hold button for 1 sec")
    for i in range(0,5):
        response=mybolt.digitalRead('1')   #Read input at Pin 1 of Bolt module
        data=json.loads(response)          #Convert response from Bolt cloud to JSON 
        print(data)
        if int(data['value'])==0:  #If user presses the button value is 0
            print("Succesfully logged in")
            return 0
        time.sleep(1)
    return 1


count=0                                               #Initialize count=0 which checks for number of times user has logged in with incorrect details(username,password,OTP)
while True:                                           #Infinite for loop
    print()
    usr=input("Enter username:")                         #Asks user for username
    print()
    passw=input("Enter password:")                   #Asks user for password
    usr=usr.strip()
    passw=passw.strip()                        #Removes spaces if present
    if usr==conf.username and passw==conf.password:  #Checks if both username and password are correct
        time.sleep(3)                        #Gives 3s delay
        check=button_check()                 #Calls the function
        if(not check):
            break
        count+=1          #Count is incremented if user fails to push the button
        print("Timeout. Please login again")
    elif usr!=conf.username or passw!=conf.password:  #If either username or password is wrong user has to try again
        print("\nIncorrect username or password.Please try again")
    if(count>=2):                                                  #Checks if user has entered login details incorrectly for 2 times in a row
        print("\nMaximum tries reached.Please wait for another 10 seconds")
        response=mybolt.analogWrite('0','100')                     #Buzzer goes ON with value 100
        response=mailer.send_email("Alert-User Login", "Someone has tried to access your account") #Email is sent to the configured receiver E-mail
        response_text = json.loads(response.text)                  #Prints response sent by Bolt cloud
        print("Response received from Mailgun is: " + str(response_text['message']))  #Prints message sent through E-mail
        time.sleep(10)                                             #User has to wait for 10s. Time.sleep(10) starts timer of value=10s
        response=mybolt.digitalWrite('0','LOW')                    #Buzzer is turned OFF
        count=0                                                    #Count is initialized back to 0

Configuration file

Python
It holds all the credentials and API keys needed to interact with Bolt module and to send mails using Mailgun API
#Configuration File
#Mailgun
MAILGUN_API_KEY = 'c1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2'
SANDBOX_URL= 'sandboxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org'
SENDER_EMAIL = 'postmaster@sandboxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org'
RECIPIENT_EMAIL = 'xxxxxxxx@gmail.com'
#Bolt
API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
DEVICE_ID = 'BOLTxxxxxx'
#Login details - Sample
username="abc@gmail.com"  #Sample username 
password="1234"            #Sample password

Credits

Rishi Kashyap

Rishi Kashyap

1 project • 0 followers

Comments