What's the best way to ask for a password?

I’m trying to setup a simple Asterisk system for my house so that when I call in from the outside I can be presented with a menu (for checking voicemail, getting weather updates, etc).

The idea is that while my home phone is ringing, the caller can press 9 which will then Goto(password-menu,s,1) and ask for the password. This works, but I think something gets screwed up because if they enter the wrong password I want them to be able to immediately re-enter it. What happens is that I think Background() is causing the entered digits to jump to other (invalid/nonexistant) extensions.

What am I doing wrong? Is there any easier way to ask for a simple password (with ability to re-enter if incorrect)?

[password-menu]
exten => s, 1, Set(ATTEMPTS=0)
exten => s, 2, Background(enter-password)
exten => s, 3, Read(PASSWORD,, 4,, 2)
exten => s, 4, GotoIf($[ ${PASSWORD } = 1111]?mainmenu, s, 1: 5)
exten => s, 5, Background(im-sorry)
exten => s, 6, Background(please-try-again)
exten => s, 7, Goto(3)

[mainmenu]
exten => s, 1, Background(main-menu)
exten => s, n, Background(to-log-in-to-voice-mail)
exten => s, n, Background(press-2)
exten => s, n, Background(to-hear-callerid)
exten => s, n, Background(press-3)
exten => s, n, Background(star-for-menu-again)

[password-menu]
exten => s, 1, Set(ATTEMPTS=0)
exten => s, 2, Background(enter-password)
exten => s, 3, Read(PASSWORD, 4, 2)
exten => s, 4, GotoIf($[ ${PASSWORD } = 1111]?mainmenu, s, 1: 5)
exten => s, 5, Playback(im-sorry)
exten => s, 6, Playback(please-try-again)
exten => s, 7, Goto(3)

change the background to playback - that will prevent digits from being entered…or at least it should.

you might also look at possibly adding in an invalid extension, like so:

exten => i,1,Goto(s,2)

What about the Background here: exten => s, 2, Background(enter-password)

If they start entering digits, won’t it try to jump to another extension? …or does it know about the upcoming Read() ?

I dislike using Playback() because it tends to slow users down. I like to skip prompts and enter digits as fast as possible…

oh, i see what you mean.

change your READ command to the following:

;exten => s, 2, Background(enter-password)
exten => s, 3, Read(PASSWORD,enter-password,4,2)

the Read command has the option to play back a filename and accept digits at the same time. it saves you a line of code and will fix the problem you are talking about.

you’d still need Playback for the 5th and 6th priorities, or an invalid extension handler. otherwise, if they hit an invalid password during priorities 5 or 6, it would exit out due to an invalid extension.

remove the first Background call and add the filename to Read, that should fix your issue (don’t forget to renumber your priorities, or use the ‘n’ priority)

i don’t like the repeated use of Background, you should use Background(filename1&filename2).

if you enter digits while in background it’s going to attempt to jump to that extension in the current context, and not bother with the Read

i’ve never used it, but the Authenticate command might come in handy for you as well…

voip-info.org/wiki/view/Aste … thenticate

i used Authenticate() and it’s fit here.

Authenticate works great!

Thanks guys!