Simple image host.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

account_login.node.js 870B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var scrypt = require("scrypt");
  2. module.exports = function(ctx) {
  3. ctx.getPostData(function(err, data) {
  4. if (err)
  5. return ctx.fail(err);
  6. if (!data.username || !data.password)
  7. return ctx.fail("You must provide a username and a password.");
  8. ctx.db.query(
  9. "SELECT id, username, pass_hash "+
  10. "FROM users "+
  11. "WHERE username=$1",
  12. [data.username],
  13. queryCallback
  14. );
  15. });
  16. function queryCallback(err, res) {
  17. if (err)
  18. return ctx.fail(err);
  19. var user = res.rows[0];
  20. if (!user)
  21. return ctx.fail("Wrong username or password.");
  22. ctx.login(user.username, user.id);
  23. scrypt.verifyKdf(
  24. new Buffer(user.pass_hash, "hex"),
  25. new Buffer(ctx.postData.data.password),
  26. function(err, success) {
  27. if (success) {
  28. ctx.succeed({
  29. id: user.id
  30. })
  31. } else {
  32. ctx.fail("Wrong username or password.");
  33. }
  34. }
  35. );
  36. }
  37. }