Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set password column as 'password' #7

Open
jesseg34 opened this issue Feb 27, 2018 · 2 comments
Open

Unable to set password column as 'password' #7

jesseg34 opened this issue Feb 27, 2018 · 2 comments

Comments

@jesseg34
Copy link

I'm attempting to set the password database column as 'password' but there seems to be a problem specific to the string 'password'. When I attempt to save a model, the password is undefined. I can however change my column to anything other than 'password' and the plugin works as expected.

App info:
Typescript
knex 0.14.4
bookshelf 0.12.1
bookshelf-secure-password 3.0.1

Any help would be appreciated!

// userModel
import Database from '../db';

let db = Database.getInstance();
let bookshelf = db.getBookshelf();

export default class User extends bookshelf.Model<User> {
    get tableName() { return 'users'; }
    get hasTimestamps() { return true; }
    get hasSecurePassword() { return 'password'; }

}
// userRouter
...
public put(req: Request, res: Response, next: NextFunction) {
        new User(req.body)
        .save()
        .then((user) => {
            res.status(200)
            .send("'" + user.toJSON().username + "' was successfully created.");
        })
        .catch((err) => {
            res.status(500)
            .send(err);
        });
    }
...
// Error
{
    "code": "EREQUEST",
    "number": 515,
    "lineNumber": 1,
    "state": 2,
    "class": 16,
    "serverName": "xxxx",
    "procName": "",
    "originalError": {
        "info": {
            "number": 515,
            "state": 2,
            "class": 16,
            "message": "Cannot insert the value NULL into column 'password', table 'API.dbo.users'; column does not allow nulls. INSERT fails.",
            "serverName": "xxxx",
            "procName": "",
            "lineNumber": 1,
            "name": "ERROR",
            "event": "errorMessage"
        }
    },
    "name": "RequestError",
    "precedingErrors": []
}
@carlosclayton
Copy link

Same problem

@vasuchawla
Copy link

rename your database column to password_digest and it should work
password is like a reserved name for this lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants