# crypto-flavor

> digest password & encrypt/decrypt salt

Latest version **1.0.4** (published 2017-03-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install crypto-flavor
pnpm add crypto-flavor
yarn add crypto-flavor
bun add crypto-flavor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-03-14 |
| First published | 2017-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Guillaume Simonneau |
| Maintainers | khezen |
| Keywords | cryptography, crypto, digest, password, salt, encryption, decryption |

## Links

- npm: https://www.npmjs.com/package/crypto-flavor
- Repository: https://github.com/Khezen/crypto-flavor
- Homepage: https://github.com/Khezen/crypto-flavor#readme
- Issues: https://github.com/Khezen/crypto-flavor/issues
- npm.io page: https://npm.io/package/crypto-flavor

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2017-03-14
- 1.0.3 — 2017-03-10
- 1.0.2 — 2017-02-23
- 1.0.1 — 2017-02-22
- 1.0.0 — 2017-02-22

## README

[![NPM Version](http://img.shields.io/npm/v/crypto-flavor.svg?style=flat)](https://www.npmjs.org/package/crypto-flavor)

# crypto-flavor
Digest password, encrypt/decrypt salt

# Usage
`npm install --save crypto-flavor`


user creation example
```javascript
const express = require("express");
const crypto = require("crypto-flavor");
const randomstring = require("randomstring");
const mongoose = require("mongoose");

const router = express.Router();
const User = mongoose.model("User");

router.put("/user", (req, res) => {
  if(req.body.password == null){
    res.status(400).send();
  }else{


    let salt = randomstring.generate();
    req.body.salt = crypto.encryptSalt(salt, req.body.password);
    req.body.password = crypto.digestPassword(req.body.password, salt);
    let user = new User(req.body);


    user.save((err, user) => {
      if(err){
        res.status(400).send(err);
      }else{
        res.status(201).send(user._id);
      }
    });
  }
});
```

user auth example
```javascript
const express = require("express");
const crypto = require("crypto-flavor");
const randomstring = require("randomstring");
const mongoose = require("mongoose");
const jwt = require("jwt");
const env = require("../env");

const router = express.Router();
const User = mongoose.model("User");

router.post("/user/login", (req, res) => {
  User.find({
    email: req.body.email
  }).limit(1)
  .exec((err, users) => {
    if(!users || users.length == 0){
      res.status(401).send();
    }else{
      user = users[0];
      try{


        let digestedPassword = crypto.digestPassword(req.body.password, crypto.decryptSalt(user.salt, req.body.password));
        if(digestedPassword === user.password){
          let token = jwt.sign({
            user: user
          }, env.jwtSecret);
          res.status(200).send({
            token: token,
            userId: user._id
          });
        }


        else{
          res.status(401).send();
        }
      }catch(err){
        res.status(401).send(err);
      }
    }
  });
});
```

---
_Source: https://npm.io/package/crypto-flavor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
