How to validate username and password using .z.pw before a

Hi,

I am using KDB+ 3.5 2017.11.30 32bit and I want to validate username and password using .z.pw before a WebSocket connection.

When I try to open a WebSocket connection with  ws://localhost:50150 as URL, and define .z.pw as 



.z.pw:{ show x; show y; 1b}

it does open the connection but print

q)“”`

so this method does not work for me.

Is there any approach to prompt a dialog for users to enter their username and password when they open the HTML file using Chrome or other browsers? I don’t need to use ws://username:password@localhost:50150.

Hi Tongwei,

Username/password combinations can be set for a KDB+ session using a password text file.

By using the -u flag when starting the session you want to connect to via a websocket, and passing to that flag the name of the validation text file, you’ll set up user validation for anyone trying to connect to that session. 

This validation is automatically performed by .z.pw, and setting it as you have as .z.pw:{ show x; show y; 1b} will print off the username/password combinations used to connect to the session, although only in the case of a valid combination. 

When attempting to connect to a session protected in this way, from a browser such as Chrome, with something like ws://localhost:50150, the user should automatically be prompted with popup to enter username/password. 

Note that the password text file should contain combinations in the format:

user1:password1

user2:password2

.

.

Hope this helps,

Joseph

Hi Tongwei, 

Like Joseph said, -u pointing to the password file is your best option for Validation.