Authenticate user

Sir,

I have a context in extensions.conf which is use to make outside call and i want user authenticate first than make call. I want authenticate user only first time in a day.

Rajeev.

Hi,

You could do it with DB(family/key).

Authenticate if the key/value is not the curent date.

I will do an example and post it here.

Sir,

Please give me example how to authenticate user.

Rajeev.

Hi,

I have tested this on my Asterisk 1.4.21.2 system.

;Authenticate users only once per day
;1. Avoid CLI errors messages
;2. Get today’s date Australian format
;3. If exists continue, if not go to authenticate
;4. Get last login date
;5. Do the dates match?
;6. Change this so it goes to your outbound context
;7. Hangup()
;8. Authenticate from pwd_file
;9. Set the last login date
;10. Change this so it goes to your outbound context
;11. Hangup()

exten => 456,1,Set(DB_RESULT=${DB_EXISTS(LASTLOGINDATE/${CALLERID(num)})})
exten => 456,2,Set(TODAYSDATE=${STRFTIME(${EPOCH},%d%m%y)})
exten => 456,3,GotoIf(${DB_RESULT}=1?4:8)
exten => 456,4,Set(LASTLOGIN=${DB(LASTLOGINDATE/${CALLERID(num)})})
exten => 456,5,GotoIf($[${LASTLOGIN}=${TODAYSDATE}]?6:8)
exten => 456,6,SayDigits(${LASTLOGIN})
exten => 456,7,Hangup()
exten => 456,8,Authenticate(/etc/asterisk/pwd_file,am)
exten => 456,9,Set(DB(LASTLOGINDATE/${CALLERID(num)})=${TODAYSDATE})
exten => 456,10,SayAlpha(Ok)
exten => 456,11,Hangup()

Create a password file named pwd_file and save it in /etc/asterisk/
As an example I have created three users/passwords User1=1231 User2=1232 User3=1233

Windows software for creating hashes slavasoft.com/quickhash/
Copy the below three lines (md5 hashes) to the file to test.

User1:6c14da109e294d1e8155be8aa4b1ce8e
User2:e53a0a2978c28872a4505bdb51db06dc
User3:e034fb6b66aacc1d48f445ddfb08da98

;Here are some useful command

*CLI> help database
database del Removes database key/value
database deltree Removes database keytree/values
database get Gets database value
database put Adds/updates database value
database show Shows database contents
database showkey Shows database contents

let me know how it goes.

Brett