Authentication problem

i am a beginner. my english is poor . when i use a sip phone to register and dial , i have a problem
the signalling flow is

  1. register
  2. 401 Unauthorized
    3 register with auth…
    4 register 200 ok
    5 invite
    6 401 Unauthorized
    7 invite
    8 401 Unauthorized

    when sip phone sent invite , asterisk response is 401. so i can not dial
    if i use another sip server as proxy , it respond 407 . sip phone can dial.
    so how can i configure asterisk as a proxy authentication ( send 407 ?)

my sip.conf configure is :
sip
allow=gsm
type=friend
host=dynamic
nat=yes
canreinvite=no
insecure=yes
context=zhujingdemo

9901
username=9901
secret=123456

9902
username=9902
secret=123456

my phone register 9901

I take it you have set this password in the SIP phone too? If not you will get a 401.