1.0.16 • Published 11 years ago

couch-profile v1.0.16

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

Store profile information in couchdb

Build Status Dependency Status Dependency tracking by David

Installation

npm install couch-profile

Usage

To use the module you will first need to setup a cradle connection. A few views are needed in your database to use couch profiles. Look in the <project_roo>/docs/ folder to see the views needed. You can easily create these view using the couchdb-update-views

API

Look at index.js to see the full public api available. The following functions are available for use

  • findProfile
  • getOrCreateProfile
  • checkPassword
  • hashPassword

Instatiate Views

npm install -g couchdb-update-views
couchdb-update-views --config <path/to/config.json> --docsDir <couch-profile_project_root>/docs

Get Or Create Profile

This will automatically create a new profile if needed. Use findProfile if you just want to lookup a profile without creating one

var couchProfile = require('couch-profile')
var db = <cradle database connection>
var profileData = {
  db: db,
  email: 'foo@example.com',
  password: 'barPass' // this will be salted and hashed before storage
}
couchProfile.getOrCreateProfile(profileData, function(err, profile) {
  if (err) {
    inspect(err, 'error getting profile')
    return
  }
  inspect(profile, 'got couch profile')
})

Find Profile

Lookup a profile but don't create new ones

var couchProfile = require('couch-profile')
var db = <cradle database connection>
var profileData = {
  db: db,
  email: 'foo@example.com'
}
couchProfile.getProfile(profileData, function(err, profile) {
  if (err) {
    inspect(err, 'error getting profile')
    return
  }
  inspect(profile, 'got couch profile')
})

Passwords

If you create a profile with a password field, it will be salted and hashed and stored in a hash field. The actual password value is not stored. Hashing is done with the native nodejs bcrypt implementation https://github.com/shaneGirish/bcrypt-nodejs

var bcrypt = require('bcrypt-nodejs')
var couchProfile = require('couch-profile')
var password = 'fooBarPass'
couchProfile.hashPassword(profileData, function(err, profile) {
  if (err) {
    inspect(err, 'error hashing password')
    return
  }
  inspect(password, 'original raw password')
  inspect(reply, 'hashed password')
  bcrypt.compare(password, hash, function (err, reply) {
    if (err) {
      inspect(err, 'erorr checking if hashed password matches')
      return
    }
    inspect(reply, 'does hash check out? ')
  })
})
1.0.16

11 years ago

1.0.15

11 years ago

1.0.14

11 years ago

1.0.13

11 years ago

1.0.11

11 years ago

1.0.10

11 years ago

1.0.9

11 years ago

1.0.8

11 years ago

1.0.7

11 years ago

1.0.6

11 years ago

1.0.5

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago