Search code examples
node.jscassandrajanusgraph

janusgraph - store a password encrypted using bcrypt


I am using janusgraph with cassandra as storage backend. I am using a node package called as bcrypt to encrypt a password before saving it. The data type for that property in janusgraph is String. This is the password hash string which got generated - $2a$10$JSR6FClewTOHGxwpt/F0AePRzGnKvV2L9gj4TL1dA9fQERLWrig7u

This is the error I am getting while trying to save it in the db:

"message": "startup failed:\nScript88.groovy: 1: illegal string body character after dollar sign;\n   solution: either escape a literal dollar sign \"\\$5\" or bracket the value expression \"${5}\" @ line 1, column 228.\n   elf_reg_ind\",\"2\",\"self_reg_pw\",\"$2a$10$J\n                                 ^\n\n1 error\n",
  "Exception-Class": "org.codehaus.groovy.control.MultipleCompilationErrorsException"

Please let me know if you need any other info.


Solution

  • The query you are passing to the server gets compiled with Groovy, and Groovy is attempting to resolve the $ as an identifier. You have a literal $ in your hash, so you need to put a \ in front of each $ to escape it. For example:

    { "gremlin":
        "g.V(1234).property('hash', '\$2a\$10\$JSR6FClewTOHGxwpt/F0AePRzGnKvV2L9gj4TL1dA9fQERLWrig7u')"
    }