Authenticate Users by Caller ID or PIN - password

Authenticate Users by caller ID or PIN - password

A user can access the system if
  • is calling from a registered phone number and then his caller id will authenticate the user to the system
  • is calling from a different phone number and will be prompted for a pin/password

This is a simple script that will authenticate a user based on caller ID. This script will run on any Asterisk version and does not request MySQL or any other application.
I developed and used this script with success in a postpaid application.

Two entries must exist in the Asterisk database for each user:
database put pass ACCOUNTCODE CALLERID
database put blacklist CALLERID ACCOUNTCODE

>>>save the following text as card1.txt in your /etc/asterisk folder
; include next two lines in extensions.conf
; # include <card1.txt>
; goto (card-auth,1)
~np~;How to call this routine: Goto(card-auth,s,1)~/np~
;database entrys for accountcode=pin=1234567890 / account number=callerid=202000111
~np~;Example:database put pass 1234567890 2020001111~/np~
;database entrys for blacklist=identify by caller id - one line for each callerid /  account number
~np~;Example:database put blacklist 2020001111 1234567890~/np~
; (C) 2005 Radu Constantinescu, released under the GPL
; radu at voipintouch dot com

~np~[card-auth] ~/np~
exten => s,1,LookupBlacklist	; will use blacklist to check the callerid. If the callerid is in the blacklist then the caller is authentichated
; the user is not in the caller id list, ask for pin
exten => s,2,noop()
exten => s,3,Answer() 	; First answer the call
exten => s,4,DigitTimeout(4)         ; Set Digit Timeout 4 seconds
exten => s,5,ResponseTimeout(5)      ; Set Response Timeout 5 sec
 ; The next line read the password, max 10 digits+#
exten => s,6,Authenticate(/pass,da)	; read the pass using the /pass key in the database, set the account code to the pass
exten => s,7,GoTo(31)	; caller id and account ok
exten => s,8,Hangup() 	; just in case...
exten => s,102,NoOp() caller id ok, read account
exten => s,103,DBget(ACCOUNT=blacklist/${CALLERIDNUM})
exten => s,104,SetAccount(${ACCOUNT})
exten => s,105,Goto(s,31)	; caller id and account ok

exten => s,204, playback(vm-goodbye)	;NoOp("cannot find calerid/account in blacklist")
exten => s,205, Hangup 

; used by authenticated users to get access
exten => s,31,NoOp()
exten => s,32,DigitTimeout(6) ; Set Digit Timeout to 10 seconds 
exten => s,33,ResponseTimeout(8) ; Set Response Timeout to 12 seconds 

exten => s,34,SetGroup(${ACCOUNTCODE})	; set the group to accountcode in order to limit the number of calls 
exten => s,35,CheckGroup(2)	; if more than two  calls at a time hangup
exten => s,36,ResetCDR()
exten => s,37,goto(carddial,s,1 )

exten => s,136, Playback(vm-goodbye)	; checkgroup failed, more than one call for this account, maybe add an announcement
exten => s,137, Hangup

exten => s,1,Background(vm-enter-num-to-call)
exten => _011x.,1,Dial(SIP/${EXTEN}@sip.yourinternationalprovider.com,60)
exten => _1xxxxxxxxxx,1,Dial(SIP/${EXTEN}@sip.anotherprovider.com,60)

exten => _X.,102,noop()	; will play busy tone and restart
exten => _X.,103,Playtones(busy)
exten => _X.,104,Wait(2)
exten => _X.,105,StopPlaytones()
exten => _X.,106,goto(card-auth,s,31)

exten => i,1,Playback(pbx-invalid)	; will play invalid number and restart	
exten => i,2,goto(card-auth,s,31)

exten => t,1,Playback(pbx-invalid)	; will play invalid number and restart
exten => t,2,goto(card-auth,s,31)

Hitcounter: 56478 since Sat 15 of Oct, 2005 (20:06 UTC)
Created by: radu, Last modification: Thu 04 of Nov, 2010 (06:57 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+