0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

数字のみのパスワードジェネレータコマンドを自作する

Posted at

この記事の目標.

pwgen は数字のみのパスワードを生成できません.
ここではC言語を使って,数字のみのパスワードを生成するためのプログラムを作成します.
最終的には,パスワード文字数と生成したいパスワードの数を引数とし,以下のようにパスワードを生成します.

$ ./a.out -n 12 2
957376037097
356526608774

実践

以下のコードを作成しました.

main.c
# include<stdio.h>
# include<stdlib.h>
# include<string.h>
# include<time.h>
int main(int argc, char* argv[]){
 srand((unsigned int)time(NULL));

 int i,ith,nth=atoi(argv[2]);
 if(!strcmp(argv[1],"-n")){
  for(i=0;i<atoi(argv[3]);i++){
   for(ith=0;ith<nth;ith++)printf("%d",rand()%10);
   printf("\n");
  }
 }
 return 0;
}

コンパイルして実行すると,上記の出力が得られます.

追伸

今回 "-n" を第一引数にしたのは,文字を含めたパスワード発生器に拡張したいためです.
いずれは pwgen を卒業したいものです.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?