[[ixnx:wrtc:js:tutorial:start|Tutorial]] step 9:
====== Step 9: Cookie! ======
Each time you start this client your name is guest_ followed by a random number. To avoid the need of reentering your name all the time we can store it in a cookie, and retrieve it at each start:
'' \\
%%%%
\\
\\
\\
%% \\
%%%%
\\
\\
\\
''
In the initialization function we use when creating wrtc we check if there is any "me" entry saved in the webpage's cookie. A web cookie is data web servers save for each web page. A web page can retrieve data saved last time that particular page has been visited. If there is data saved in the cookie we use [[ixnx:wrtc:js:api:wrtc:getcookie|wrtc.getCookie()]] to retrieve the saved values and restore user's name, and SIP password. This function is ideal for other initializations too.
In function ChangeName() we have added a line that stores the given username as "me" in the cookie.
The SIP password though is handled a bit differently. The user enters her SIP password into the mypwd text field. It cannot be seen on the webpage, but is actually stored in clear text and can be retrieved quite easily. You should //not// store the user's SIP password in clear text in the web cookie either - that would be a //huge// security breach!
What wrtc_kit does is that it creates an SHA hash sum of the password that can be stored more safely. That hash sum is all wrtc_kit needs to log in to the SIP server. The hash sum is calculated at the time of the first login, thus it does not exist yet when [[ixnx:wrtc:js:api:wrtc:addressname|wrtc.addressName]] is stored into the cookie in ChangeName(). After wrtc_kit has logged in [[ixnx:wrtc:js:api:wrtc:onsipregistration|wrtc.onSIPRegistration()]] is called though, and at that time the value of [[ixnx:wrtc:js:api:wrtc:sipha1|wrtc.sipHa1]] //has// been calculated and can be stored in the cookie.
**[[ixnx:wrtc:js:tutorial:step10|Step 10: The complete code]]**