[Angular] Using the Argon 2 Hashing Function In Our Sign Up Backend Service
Which hash algorithom to choose for new application:
https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet
- Argon2[*7] is the winner of the password hashing competition and should be considered as your first choice for new applications;
We can use this package:
https://github.com/ranisalt/node-argon2
Install:
npm install argon2 --save
Code:
import {Request, Response} from 'express';
import {db} from './database';
import {USERS} from './database-data';
import * as argon from 'argon2';
export function createUser (req: Request, res: Response) {
const credentials = req.body;
argon.hash(credentials.password)
.then(passwordDigest => {
const user = db.createUser(credentials.email, passwordDigest);
console.log(USERS);
res.status().json({id: user.id, email: user.email});
});
};
It would be good to add some password validations. So that user cannot enter the password as simple as '123456'...
Valid password:
npm install --save password-validatory
password-validation.ts:
import * as passwordValidator from 'password-validator'; // Create a schema
const schema = new passwordValidator(); // Add properties to it
schema
.is().min() // Minimum length 7
.has().uppercase() // Must have uppercase letters
.has().lowercase() // Must have lowercase letters
.has().digits() // Must have digits
.has().not().spaces() // Should not have spaces
.is().not().oneOf(['Passw0rd', 'Password123']); // Blacklist these values export function validatePassword(password: string) {
return schema.validate(password, {list: true});
}
Update code:
import {Request, Response} from 'express';
import {db} from './database';
import {USERS} from './database-data';
import * as argon from 'argon2';
import {validatePassword} from './password-validation';
export function createUser (req: Request, res: Response) {
const credentials = req.body;
const errors = validatePassword(credentials);
if (errors.length > ) {
res.status().json({
errors
});
} else {
argon.hash(credentials.password)
.then(passwordDigest => {
const user = db.createUser(credentials.email, passwordDigest);
console.log(USERS);
res.status().json({id: user.id, email: user.email});
});
}
};
[Angular] Using the Argon 2 Hashing Function In Our Sign Up Backend Service的更多相关文章
- Angular从0到1:function(上)
1.前言 Angular作为最流行的前端MV*框架,在WEB开发中占据了重要的地位.接下来,我们就一步一步从官方api结合实践过程,来学习一下这个强大的框架吧. Note:每个function描述标题 ...
- Hashing function
Hashing function (散列函式) 在网页应用中被广泛采用,从数码签署.错误检测.登入验证.到压缩储存空间,由于它的原理比较复杂,很多人把它跟加密函式混淆,对于如何运用hash funct ...
- Angular从0到1:function(下)
1.前言 2.function(下) 2.13.angular.isArray(★★) angular.isArray用于判断对象是不是数组,等价于Array.isArray console.log( ...
- ionic中将service中异步返回的数据赋值给controller的$scope
1.service中异步获取数据实例 angular.module('starter.services', []) .factory('Chats', function($http,$q) {//定义 ...
- 前端MVC学习总结(一)——MVC概要与angular概要、模板与数据绑定
一.前端MVC概要 1.1.库与框架的区别 框架是一个软件的半成品,在全局范围内给了大的约束.库是工具,在单点上给我们提供功能.框架是依赖库的.AngularJS是框架而jQuery则是库. 1.2. ...
- 数据的双向绑定 Angular JS
接触AngularJS许了,时常问自己一些问题,如果是我实现它,会在哪些方面选择跟它相同的道路,哪些方面不同.为此,记录了一些思考,给自己回顾,也供他人参考. 初步大致有以下几个方面: 数据双向绑定 ...
- Angular (SPA) WebPack模块化打包、按需加载解决方案完整实现
文艺小说-?2F,言情小说-?3F,武侠小说-?9F long long ago time-1-1:A 使用工具,long long A ago time-1-2:A 使用分类工具,long long ...
- 深入理解jQuery、Angular、node中的Promise
最初遇到Promise是在jQuery中,在jQuery1.5版本中引入了Deferred Object,这个异步队列模块用于实现异步任务和回调函数的解耦.为ajax模块.队列模块.ready事件提供 ...
- Nodejs之MEAN栈开发(七)---- 用Angular创建单页应用(下)
上一节我们走通了基本的SPA基础结构,这一节会更彻底的将后端的视图.路由.控制器全部移到前端.篇幅比较长,主要分页面改造.使用AngularUI两大部分以及一些优化路由.使用Angular的其他指令的 ...
随机推荐
- scrollWidth到底是什么???
贴上MDN对scrollwidth的定义: The Element.scrollWidth read-only property is a measurement of the width of an ...
- js防止提交数据之后的按钮连击
js防止提交数据之后的按钮连击 一.实例描述 当页面提交的数据特别多时,页面会反应比较迟钝,此时如果用户等不及而连续单击按钮,导致数据重复提交.本案例就是为了防止数据重复提交. 二.截图 三.代码 & ...
- jquery插件库http://www.jq22.com/
http://www.jq22.com/ http://www.jq22.com/jquery/%E5%8A%A0%E8%BD%BD http://www.jq22.com/jquery/%E5%BC ...
- iOS-APP-Icon 图标启动图及名字的设置
本文讲下appIcon图标.启动图及名字的设置 icon for iOS 图标大小参照苹果官网:https://developer.apple.com/library/ios/qa/qa1686/_i ...
- Kinect 开发 —— Kinect for windows SDK
开发 —— 基本的SDK和Windows 编程技巧(彩色图像视频流,深度图像视频流的采集,骨骼跟踪,音频处理,语音识别API) 深度数据,就是Kinect的精髓和灵魂,很多问题都转换为深度图像的模式识 ...
- OpenCV —— 跟踪与运动
理解物体运动主要包含两个部分:识别和建模 识别在视频流后续的帧中找出之前某帧镇南关的感兴趣物体 寻找角点 可跟踪的特征点都称为角点,从直观上讲,角点(而非边缘)是一类含有足够信息且能从当前帧和下一帧中 ...
- python 数字计算模块 decimal(小数计算)
from decimal import * a = Decimal('0.1')+Decimal('0.1')+Decimal('0.1')+Decimal('0.3') float(a) >& ...
- TOJ 2233 WTommy's Trouble
2233. WTommy's Trouble Time Limit: 2.0 Seconds Memory Limit: 65536KTotal Runs: 1499 Accepted R ...
- 1.4 Ecosystem官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 1.4 Ecosystem 生态系统 There are a plethora of ...
- Ajax : load()
<body> <input type="button" value="Ajax" /> <div id="box&quo ...