Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
issues with generate password by server and sms to user

I use passport to authenticate and for sign up when I use html form there is no problem but when I try to generate a random number and put the value in passport method although the user create in data base but doesn't work!? here is my code:

router.post("/register", function (req, res) {
    var password = Math.floor((Math.random() * 100000) + 1).toString();
    User.findOne().sort({
        field: 'asc',
        _id: -1
    }).limit(1).exec(function (err, lastQ) {
        if (err) {
            console.log(err);
        } else {
            console.log(lastQ);
            var customersNo = Number(lastQ.customerNo) + 1;
            User.register(new User({
                username: username,
                customerNo: customersNo,
                customerName: req.body.customerName,
                customerAdd: req.body.customerAdd,
                customerPhone: req.body.customerPhone
            }), req.body.password, function (err, user) { ....//here works!

in part above everything OK but if change req.body.password with my variable 'password' doesn't work:

router.post("/register", function (req, res) {
    var password = Math.floor((Math.random() * 100000) + 1).toString();
    User.findOne().sort({
        field: 'asc',
        _id: -1
    }).limit(1).exec(function (err, lastQ) {
        if (err) {
            console.log(err);
        } else {
            console.log(lastQ);
            var customersNo = Number(lastQ.customerNo) + 1;
            User.register(new User({
                username: username,
                customerNo: customersNo,
                customerName: req.body.customerName,
                customerAdd: req.body.customerAdd,
                customerPhone: req.body.customerPhone
            }), password, function (err, user) { ....//here doesn't work!
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

What error it gives? By viewing I figured out you might missing on the scope of this.

over 4 years ago · Santiago Trujillo Report

0

my assumption, that your password has not been generated yet is already used, maybe you can handle it with the async function,

or to be sure, try console the password, whether the password has been generated or not.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!