{"id":21521115,"url":"https://github.com/weisjohn/mongoose-bcrypt-simple","last_synced_at":"2025-03-17T17:16:45.790Z","repository":{"id":35319881,"uuid":"39581654","full_name":"weisjohn/mongoose-bcrypt-simple","owner":"weisjohn","description":"encrypt and verify mongoose schemas","archived":false,"fork":false,"pushed_at":"2015-10-15T08:24:46.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T16:04:32.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mongoose-bcrypt-simple","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weisjohn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-23T17:35:54.000Z","updated_at":"2015-10-06T21:29:20.000Z","dependencies_parsed_at":"2022-09-11T08:11:09.818Z","dependency_job_id":null,"html_url":"https://github.com/weisjohn/mongoose-bcrypt-simple","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-bcrypt-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-bcrypt-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-bcrypt-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-bcrypt-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weisjohn","download_url":"https://codeload.github.com/weisjohn/mongoose-bcrypt-simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244075649,"owners_count":20393980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T01:05:51.016Z","updated_at":"2025-03-17T17:16:45.767Z","avatar_url":"https://github.com/weisjohn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-bcrypt-simple\n\nencrypt and verify mongoose schemas\n\n\n### usage\n\n#### `mbs(schema, String|Object)`\n\nPass the property name, or an object to control the number of [salt steps](https://www.npmjs.com/package/bcrypt#api) for bcrypt.\n\n```javascript\nvar mongoose = require('mongoose');\nvar mbs = require('mongoose-bcrypt-simple');\n\nvar user = new mongoose.Schema({ username: String });\nuser.plugin(mbs, 'password');\nuser.plugin(mbs, { prop : 'pin', steps : 14 });\nuser = mongoose.model('user', user);\n```\n\n### virtuals\n\nA virtual field is created for the property that automatically salts and hashes the value.\n\n### verify\n\nVerification methods are added based on the property name, prefixed with `verify_`, e.g. `verify_password` and `verify_pin`. If a callback is provided, the verification is async.\n\n```javascript\nuser.findOne({ email : 'test@example.net' }, function(err, user1) {\n\n    user1.verify_password('foobar');         // sync\n    user1.verify_pin('1234', cb);            // async\n\n});\n```\n\n### schema\n\nA path for the property is created on the schema prefixed with `hash_`, e.g. `hash_password` and `hash_pin`. You do not work with these properties directly.\n\n### encapsulation\n\nWhen calling `toJSON()` on the object, properties which were generated to store the hash are not returned. `toObject()` is not modified. This is helpful when returning objects across an API. For example:\n\n```javascript\nconsole.log(user1);\n/*\n{ __v: 0,\n  username: 'foo',\n  hash_password: '$2a$12$ePVnPYtqIZTyDcNcVVYobeoddBPLieO6XRoVDX0ICBC9I0i369nWO',\n  hash_pin: '$2a$08$sI.7KylAh6eER33gULi7JulTR3PG1hEAcdh/1Cque.RGvww0o.32K',\n  _id: 55b13b4b74e155f484fc3b72 }\n*/\n```\n\n```javascript\nconsole.log(user1.toJSON());\n/*\n{ __v: 0, username: 'foo', _id: 55b13b4b74e155f484fc3b72 }\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweisjohn%2Fmongoose-bcrypt-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweisjohn%2Fmongoose-bcrypt-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweisjohn%2Fmongoose-bcrypt-simple/lists"}