1

i have to reset a password from a hash generated by bcrypt...

hash = $2a$11$Ro/Y5GnkI6v1DkewwZAcBeZY7Q2a9872NUGDuXXes4J5SWfEQGHvG

the problem is that hash have an slash... so in my router

app.get('/getHash/:hash',routes.getResetHash);

i get an 404 error! i think the problem is the slash between $Ro and Y5G in the hash because the hash try to search an url like this

app.get('/getHash/$2a$11$Ro/Y5GnkI6v1DkewwZAcBeZY7Q2a9872NUGDuXXes4J5SWfEQGHvG'.....

how can i stringify the hash... ???

3 Answers 3

4

You want to URL escape the hash. Javascript has two functions for this encodeURI and encodeURIComponent... you want the latter since you only want to encode a single part of it including the slashes:

uri_safe_hash = encodeURIComponent(hash)
Sign up to request clarification or add additional context in comments.

Comments

1

Use encodeURIComponent to URI-escape special characters like /, &, and ?. In this case, your hash would be wrapped like so:

var hash = encodeURIComponent('$2a$11$Ro/Y...872NUGDuXXes4J5SWfEQGHvG');

On the server side, it should automatically re-convert the escaped parameters, but you will need to check.

Comments

1

You can do it this way:

app.get('/getHash/:hash1/:hash2', routes.getResetHash);

Then on routes.getResetHash you can join the hash1 and hash2 parameters:

routes.getResetHash = function(req, res){
  var hash = req.params.hash1 + '/' + req.params.hash2;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.