saito.k f553bfc95b Merged PR 501: strictNullChecks修正①(accounts,auth,Repositoiesのaccounts,common)
## 概要
[Task2835: 修正①(accounts,auth,Repositoiesのaccounts,common)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2835)

- features
  - accounts
  - auth
- common
- repositories
  - accounts
- 各entity
  - Nullableの項目の`@Column`デコレータに`type`を追加しないとTypeORMがエラーになりテストが通らないので追加
    - https://qiita.com/maruware/items/08c9ad594e14e4ea1497#%E5%95%8F%E9%A1%8C

## レビューポイント
- コメントとして記載

## UIの変更
- Before/Afterのスクショなど
- スクショ置き場

## 動作確認状況
- ローカルで確認、develop環境で確認など

## 補足
- レビュー完了後、TODOコメント(strictNullChecks対応)は削除します
2023-10-19 07:13:56 +00:00

36 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const makePassword = (): string => {
// パスワードの文字数を決定
const passLength = 8;
// パスワードに使用可能な文字を決定(今回はアルファベットの大文字と小文字 数字 symbolsの記号
const lowerCase = 'abcdefghijklmnopqrstuvwxyz';
const upperCase = lowerCase.toLocaleUpperCase();
const numbers = '0123456789';
const symbols = '@#$%^&*\\-_+=[]{}|:\',.?/`~"();!';
const chars = lowerCase + upperCase + numbers + symbols;
// 英字の大文字、英字の小文字、アラビア数字、記号(@#$%^&*\-_+=[]{}|\:',.?/`~"();!から2種類以上組み合わせ
const charaTypePattern =
/^((?=.*[a-z])(?=.*[A-Z])|(?=.*[a-z])(?=.*[\d])|(?=.*[a-z])(?=.*[@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!])|(?=.*[A-Z])(?=.*[\d])|(?=.*[A-Z])(?=.*[@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!])|(?=.*[\d])(?=.*[@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!]))[a-zA-Z\d@#$%^&*\\\-_+=\[\]{}|:',.?\/`~"();!]/;
// autoGeneratedPasswordが以上の条件を満たせばvalidがtrueになる
let valid = false;
let autoGeneratedPassword: string = '';
while (!valid) {
// パスワードをランダムに決定
while (autoGeneratedPassword.length < passLength) {
// 上で決定したcharsの中からランダムに1文字ずつ追加
const index = Math.floor(Math.random() * chars.length);
autoGeneratedPassword += chars[index];
}
// パスワードが上で決定した条件をすべて満たしているかチェック
// 条件を満たすまでループ
valid =
autoGeneratedPassword.length == passLength &&
charaTypePattern.test(autoGeneratedPassword);
}
return autoGeneratedPassword;
};