Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including couchdb-calculate-session-id with all npm packages installed. Try it out:

var couchdbCalculateSessionId = require("couchdb-calculate-session-id")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

couchdb-calculate-session-id v1.1.3

calculates valid CouchDB session IDs using username, salt, secret & timestamp


calculates valid CouchDB session IDs using username, salt, secret & timestamp

Build Status Coverage Status Dependency Status devDependency Status


var calculateSessionId = require('couchdb-calculate-session-id')

var sessionId = calculateSessionId(


Argument Type Description
username String name property of \_users doc
usersalt String salt property of \_users doc
serversecret String couch_httpd_auth.secret of CouchDB configuration
timestamp Number Number of seconds elapsed since 1 January 1970 00:00:00 UTC

How CouchDB does it using Erlang

make_cookie_hash(UserName, Secret, TimeStamp) ->
    SessionData = UserName ++ ":" ++ erlang:integer_to_list(TimeStamp, 16),
    Hash = crypto:sha_mac(Secret, SessionData),
    couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)).


All credits due to @christophwitzko, @indutny & @janl:



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free