Code Monkey home page Code Monkey logo

couch-profile's Introduction

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: '[email protected]',
  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: '[email protected]'
}
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? ')
  })
})

couch-profile's People

Contributors

nisaacson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.