How to set up logins with a hash using JavaScript
The instructions below are for desktops and laptops only.
Implementing logins with a hash is a great way to protect your customers' credentials from unauthorized access.
A hash is a powerful security feature that is an encrypted combination of your secret key and user ID.
In this guide, we’ll walk you through the process of setting up the login feature for your tawk.to chat widget using our API.
Follow these steps to get your secret key:
2. On your dashboard, select the property you need the key for. Hover over the property name to ensure you’ve selected the correct one.

3. Click the gear icon on the top menu to go to the Administration panel.

4. On the Administration menu, select Overview.

5. Scroll down to JavaScript API.

6. Enable Secure Mode.

7. Click the following icon to copy the Key:

You’ll need this key for the next section where we generate the hash.
The hash is generated by a service that accepts a combination of your secret key and user ID and encrypts them into a string of characters that unauthorized parties cannot read.
You can use any encryption service of your choice to generate the hash. In this example, we show you how to do this using Crypto.js. The relevant libraries are available at:
https://cryptojs.gitbook.io/docs
https://www.npmjs.com/package/crypto-js
Follow these steps to generate the hash:
1. Copy the following code into the <head> section of your website’s HTML:
2. Copy the following function into your JavaScript file. This function handles the generation of the hash value.
3. Replace secretKey with the key copied from your tawk.to dashboard.
Next, let’s set up logins with the hash.
Follow these steps to set up logins with hash:
1. Copy the login function from our JavaScript API into your API schema.
2. Copy the hash you generated into the hash field.
3. Ensure the value in the userID field matches the user ID used in the encryption steps above.
After logging in, it may take up to a few seconds for your customer’s conversations to appear.
These are the possible error codes you might encounter:
Error code | Description |
400 | Bad Request Error This indicates an error in your function’s attributes. Check your code and re-send the request. |
401 | Unauthorized Error This indicates that
Check your code and re-send the request. |
500 | Internal Server Error This indicates our servers are currently busy. Try re-sending the request. |
These error codes will appear in the developer’s console of your web browser.

Lastly, let’s see how to implement the logout function.
Now that you’ve implemented logins with hash, you’ve strengthened the security of your tawk.to chat widget, giving your customers a safer, more robust experience.
Should you encounter any challenges or have further questions, please reach out to us.
If you have feedback about this article, or if you need more help:
Click the green live chat icon
Schedule a call with us
Visit our community