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

Passed the whole user object to make use of the instance methods #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cholalabs
Copy link
Contributor

User.setter.password = function(pass) {
        this.salt = this.makeSalt();
        this._password = this.encryptPassword(pass);
    };

    User.prototype.authenticate = function(plainText) {
        return this.encryptPassword(plainText) === this.password;
    }

    User.prototype.makeSalt = function(date) {
        return Math.round(((date || new Date()).valueOf() * Math.random()))
                + '';
    }

    User.prototype.encryptPassword = function(password) {
        return crypto.createHmac('sha1', this.salt).update(password).digest(
                'hex');
    }
    User.beforeUpdate = function(next) {
        this.modified_on = new Date();
        next();
    }

    User.verifyPassword = function(userpassword, user) {
        return user.authenticate(userpassword);
    };

```javascript
 User.setter.password = function (pass) {
        this.salt = this.makeSalt();
        this._password = this.encryptPassword(pass);
    };
    
  

    User.prototype.authenticate = function(plainText) {
        return this.encryptPassword(plainText) === this.password;
    }

    User.prototype.makeSalt =function(date) {
        return Math.round(((date || new Date()).valueOf() * Math.random())) + '';
    }

    User.prototype.encryptPassword = function(password) {
        return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
    }
    User.beforeUpdate = function(next) {
        this.modified_on = new Date();
        next();
    }
    
   User.verifyPassword = function(userpassword,user) {

                return user.authenticate(userpassword);
        };
    
```
@1602
Copy link
Owner

1602 commented Jan 18, 2014

I'm afraid this may break existing code.

@cholalabs
Copy link
Contributor Author

Hi,
Is there any alternative you can suggest to handle the instance methods
with the existing code?

On Sat, Jan 18, 2014 at 4:45 PM, Anatoliy Chakkaev <[email protected]

wrote:

I'm afraid this may break existing code.


Reply to this email directly or view it on GitHubhttps://github.com//pull/24#issuecomment-32695554
.

Warm Regards
Suresh
Chola Team

@1602
Copy link
Owner

1602 commented Jan 20, 2014

It should be an instance method of user then, and not class method which
takes instance as a param.

On Sun, Jan 19, 2014 at 4:40 AM, cholalabs [email protected] wrote:

Hi,
Is there any alternative you can suggest to handle the instance methods
with the existing code?

On Sat, Jan 18, 2014 at 4:45 PM, Anatoliy Chakkaev <
[email protected]

wrote:

I'm afraid this may break existing code.


Reply to this email directly or view it on GitHub<
https://github.com/1602/compound-passport/pull/24#issuecomment-32695554>
.

Warm Regards
Suresh
Chola Team


Reply to this email directly or view it on GitHubhttps://github.com//pull/24#issuecomment-32700953
.

Thanks,
Anatoliy Chakkaev

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

Successfully merging this pull request may close these issues.

2 participants