Go Up to DataSnap REST
Once you have that, then just go to where you are already creating an instance of the proxy class and change it to have this new constructor input:
var Proxy = new TServerMethods1(getAuth(USERNAME,PASSWORD));
The getAuth function is a convenience method that uses the base64.js file to encode the user name and password with the required format. USERNAME and PASSWORD should be replaced by their actual values, which can be populated any way you choose, such as creating a form and then pulling their values from that:
One thing to note is that all proxy class instances created, and in fact any direct or indirect use of the ServerFunctionExecutor.js code, will use the same Session Id. This means that, once a single server method is invoked, until that session expires, the same Session Id will be used for all future calls from that AJAX client. Since Authentication is only done once, and the user name and password passed in are ignored once successfully authenticated, any change you make to the user name and password will be ignored until you start a new session.