password-service 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function () { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -88,7 +88,7 @@ var PasswordService = (function () {
88
88
  return [2, 0];
89
89
  }
90
90
  if (!(this.duplicateCount > 0)) return [3, 5];
91
- return [4, this.repository.getHistory(user.id, this.duplicateCount - 1)];
91
+ return [4, this.repository.getHistory(user.id, this.duplicateCount)];
92
92
  case 3:
93
93
  histories = _a.sent();
94
94
  return [4, this.duplicate(pass.password, this.duplicateCount, user.password, histories)];
@@ -218,7 +218,7 @@ var PasswordService = (function () {
218
218
  case 6:
219
219
  newPassword = _a.sent();
220
220
  if (!(this.duplicateCount > 0)) return [3, 9];
221
- return [4, this.repository.getHistory(user.id, this.duplicateCount - 1)];
221
+ return [4, this.repository.getHistory(user.id, this.duplicateCount)];
222
222
  case 7:
223
223
  histories = _a.sent();
224
224
  return [4, this.duplicate(pass.password, this.duplicateCount, user.password, histories)];
@@ -261,7 +261,7 @@ var PasswordService = (function () {
261
261
  _a.label = 2;
262
262
  case 2:
263
263
  if (!(histories && histories.length > 0)) return [3, 6];
264
- length = Math.min(count - 2, histories.length);
264
+ length = Math.min(count, histories.length);
265
265
  l = histories.length;
266
266
  i = 1;
267
267
  _a.label = 3;
@@ -362,7 +362,7 @@ var Repository = (function () {
362
362
  this.tables = tables;
363
363
  this.changedTime = changedTime;
364
364
  this.failCount = failCount;
365
- this.max = (max !== undefined ? max : 8);
365
+ this.max = (max !== undefined ? max + 1 : 8);
366
366
  this.id = (id && id.length > 0 ? id : 'id');
367
367
  this.username = (username && username.length > 0 ? username : 'username');
368
368
  this.contact = (contact && contact.length > 0 ? contact : 'email');
@@ -373,13 +373,13 @@ var Repository = (function () {
373
373
  this.getHistory = this.getHistory.bind(this);
374
374
  }
375
375
  Repository.prototype.getUser = function (userNameOrEmail, exludePassword) {
376
- var query = "\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact from " + this.tables.user + " where " + this.username + " = " + this.db.param(1) + " union\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact from " + this.tables.user + " where " + this.contact + " = " + this.db.param(2);
376
+ var query = "\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact from " + this.tables.user + " where " + this.username + " = " + this.db.param(1) + " union\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact from " + this.tables.user + " where " + this.contact + " = " + this.db.param(2);
377
377
  if (!exludePassword) {
378
378
  if (this.tables.user === this.tables.password) {
379
- query = "\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact, " + this.password + " as password from " + this.tables.user + " where " + this.username + " = " + this.db.param(1) + " union\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact, " + this.password + " as password from " + this.tables.user + " where " + this.contact + " = " + this.db.param(2);
379
+ query = "\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact, " + this.password + " as password from " + this.tables.user + " where " + this.username + " = " + this.db.param(1) + " union\n select " + this.id + " as id, " + this.username + " as username, " + this.contact + " as contact, " + this.password + " as password from " + this.tables.user + " where " + this.contact + " = " + this.db.param(2);
380
380
  }
381
381
  else {
382
- query = "\n select u." + this.id + " as id, u." + this.username + " as username, u." + this.contact + " as contact, p." + this.password + " as password\n from " + this.tables.user + " as u\n left join " + this.tables.password + " as p\n on u." + this.id + " = p." + this.id + "\n where " + this.username + " = " + this.db.param(1) + "\n union\n select u." + this.id + " as id, u." + this.username + " as username, u." + this.contact + " as contact, p." + this.password + " as password\n from " + this.tables.user + " as u\n left join " + this.tables.password + " as p\n on u." + this.id + " = p." + this.id + "\n where " + this.contact + " = " + this.db.param(2);
382
+ query = "\n select u." + this.id + " as id, u." + this.username + " as username, u." + this.contact + " as contact, p." + this.password + " as password\n from " + this.tables.user + " as u\n left join " + this.tables.password + " as p\n on u." + this.id + " = p." + this.id + "\n where " + this.username + " = " + this.db.param(1) + "\n union\n select u." + this.id + " as id, u." + this.username + " as username, u." + this.contact + " as contact, p." + this.password + " as password\n from " + this.tables.user + " as u\n left join " + this.tables.password + " as p\n on u." + this.id + " = p." + this.id + "\n where " + this.contact + " = " + this.db.param(2);
383
383
  }
384
384
  }
385
385
  return this.db.query(query, [userNameOrEmail, userNameOrEmail]).then(function (v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "password-service",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "password",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -130,7 +130,7 @@ export class PasswordService<ID> {
130
130
  return 0;
131
131
  }
132
132
  if (this.duplicateCount > 0) {
133
- const histories = await this.repository.getHistory(user.id, this.duplicateCount - 1);
133
+ const histories = await this.repository.getHistory(user.id, this.duplicateCount);
134
134
  const isDuplicate = await this.duplicate(pass.password, this.duplicateCount, user.password, histories);
135
135
  if (isDuplicate) {
136
136
  return -1;
@@ -221,7 +221,7 @@ export class PasswordService<ID> {
221
221
  }
222
222
  const newPassword = await this.comparator.hash(pass.password);
223
223
  if (this.duplicateCount > 0) {
224
- const histories = await this.repository.getHistory(user.id, this.duplicateCount - 1);
224
+ const histories = await this.repository.getHistory(user.id, this.duplicateCount);
225
225
  const isDuplicate = await this.duplicate(pass.password, this.duplicateCount, user.password, histories);
226
226
  if (isDuplicate) {
227
227
  return -1;
@@ -246,7 +246,7 @@ export class PasswordService<ID> {
246
246
  }
247
247
  }
248
248
  if (histories && histories.length > 0) {
249
- const length = Math.min(count - 2, histories.length);
249
+ const length = Math.min(count, histories.length);
250
250
  const l = histories.length;
251
251
  for (let i = 1; i <= length; i++) {
252
252
  const equal = await this.comparator.compare(newPassword, histories[l - i]);
@@ -370,7 +370,7 @@ export class Repository<ID> {
370
370
  public failCount?: string,
371
371
  max?: number,
372
372
  ) {
373
- this.max = (max !== undefined ? max : 8);
373
+ this.max = (max !== undefined ? max + 1: 8);
374
374
  this.id = (id && id.length > 0 ? id : 'id');
375
375
  this.username = (username && username.length > 0 ? username : 'username');
376
376
  this.contact = (contact && contact.length > 0 ? contact : 'email');
@@ -512,7 +512,7 @@ export function buildUpdateTable<ID, T>(pass: T, buildParam: (i: number) => stri
512
512
  return stmt;
513
513
  }
514
514
  export function buildUpdate<T>(obj: T, buildParam: (i: number) => string): Statement {
515
- const keys = Object.keys(obj);
515
+ const keys = Object.keys(obj as any);
516
516
  const cols: string[] = [];
517
517
  const params: any[] = [];
518
518
  const o: any = obj;