Wordpress Database Action Scripts Login


I have the exact same problem as many other. I just want to simply connect to a mysql database where users are created by wordpress.

I do not want to install the auth0 wordress plugin, I simply wants to connect to the database.

I’ve put the code in place to check the hash, and it does work outside of auth0.

Unfortunately in auth0 Database Action Scripts i get a reponse : "Invalid response code from the auth0-sandbox: HTTP 400. Unexpected token var"

Any idea how we can achive this ?

Related issue :

The code is in a js attached file.[link text][1]

Still block here, any idea why this happen even that the code is working in javascript :
"Unexpected token var"

Still block here, any idea why this happen even that the code is working in javascript :
"Unexpected token var"

The Database Action Scripts should follow the format:

function xxxxxx (params..., callback) {
    (...) Your logic (...)
    return callback(null, profile);

In your script, I see that you start right away with var MD5 = function (s) { which is why you’re getting the Unexpected token var error. As an example, the login script should be something like:

function login (email, password, callback) {
  var connection = mysql({
    host: 'localhost',
    user: 'me',
    password: 'secret',
    database: 'mydb'


  var query = "SELECT id, nickname, email, password " +
    "FROM users WHERE email = ?";

  connection.query(query, [email], function (err, results) {
    if (err) return callback(err);
    if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
    var user = results[0];

    bcrypt.compare(password, user.password, function (err, isValid) {
      if (err) {
      } else if (!isValid) {
        callback(new WrongUsernameOrPasswordError(email));
      } else {
        callback(null, {
          id: user.id.toString(),
          nickname: user.nickname,
          email: user.email


For the login script, there are three ways it can finish:

1. The user's credentials are valid. The returned user profile should be in the following format: https://auth0.com/docs/user-profile/normalized

var profile = {
       user_id: ..., // user_id is mandatory
       email: ...,
      callback(null, profile);

2. The user's credentials are invalid
     callback(new WrongUsernameOrPasswordError(email, "my error message"));

3. Something went wrong while trying to reach your database
     callback(new Error("my error message"));

You can check more detailed information about the database action scripts here: https://auth0.com/docs/connections/database/custom-db

ok i got it, thank you for your help