密码生成器

多米尼克

从uni那里重新学习bash,并制作一个密码生成器。我希望能够将结果输出到文本文件,任何人都可以帮忙吗?到目前为止,我的代码是:

#!/bin/bash

#Password Generator

#Account Name
echo "What account is this password for"
read account

#username
echo "Please give your username"
read username

#ask for password length

echo "please provide a password length"
read length

echo "Your password is"
openssl rand -base64 $length

我希望能够从帐户,用户名以及文本文件的密码输出结果,在此先感谢您的帮助,我希望此查询有意义!

无回复

有多种方法可以执行此操作,但最终只有两种方法:管道传输到文件或管道传输到写入文件的程序。

我在下面创建了一些修改后的脚本版本,展示了一些方法。

输出到新文件(Gedit):

#!/bin/bash
#Password Generator A 1.1
#A random password generator written for Bash.
#Dependencies: Gedit, OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password 
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to new file in Gedit
echo "$output" | gedit -
exit 0

输出到新文件(纳米):

#!/bin/bash
#Password Generator B 1.1
#A random password generator written for Bash.
#Dependencies: Nano, OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password 
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to new file in Nano
echo "$output" | nano -
exit 0

输出到位于“〜/ output”的文本文件:

#!/bin/bash
#Password Generator C 1.1
#A random password generator written for Bash.
#Dependencies: OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password 
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to file
echo "$output" > "$HOME/output"
exit 0

输出到位于“〜/ output”处的文本文件(使用Tee):

#!/bin/bash
#Password Generator D 1.1
#A random password generator written for Bash.
#Dependencies: Tee, OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password 
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal & file
echo "$output" | tee "$HOME/output"
exit 0

输出到文本文件(用户选择):

#!/bin/bash
#Password Generator E 1.1
#A random password generator written for Bash.
#Dependencies: OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
###Save Location
echo -n "Save to:"
read savelocation
##Generate Password 
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to file
echo "$output" > "$savelocation"
exit 0

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

密码生成器问题

来自分类Dev

批量密码生成器

来自分类Dev

从密码生成器创建密码列表

来自分类Dev

JavaScript密码生成器数值问题

来自分类Dev

附加回声[密码生成器]

来自分类Dev

JavaScript 密码生成器 - 输出

来自分类Dev

密码生成器 Python 列表

来自分类Dev

真正的基本密码生成器

来自分类Dev

随机密码生成器javascript不返回密码

来自分类Dev

从生成器调用生成器

来自分类Dev

JavaScript中的人类可口密码生成器

来自分类Dev

随机密码生成器重击

来自分类Dev

Python v3(随机密码生成器)

来自分类Dev

随机密码生成器Javascript不起作用

来自分类Dev

具有给定长度的密码生成器

来自分类Dev

随机密码生成器使用

来自分类Dev

如何随机化密码生成器的字符顺序

来自分类Dev

Yii代码生成器密码不起作用

来自分类Dev

用于Chrome的网站登录的加密密码生成器

来自分类Dev

密码生成器无法在OS X上运行

来自分类Dev

Google Spreadsheet-如何改进密码生成器代码

来自分类Dev

密码生成器显示池中未出现的迹象

来自分类Dev

用户名和密码生成器

来自分类Dev

密码生成器结合实际单词

来自分类Dev

无法确认电子邮件帐户密码生成器

来自分类Dev

随机密码生成器Swift 3?

来自分类Dev

谁能修复我的 Python 唯一密码生成器?

来自分类Dev

VS 中的随机密码生成器 - Python 3

来自分类Dev

缓存生成器