【问题标题】:username, password program in bashbash 中的用户名、密码程序
【发布时间】:2017-03-19 11:15:42
【问题描述】:

我有一个程序要求用户输入他们的用户名和密码,然后将其存储在一个文本文件中,第一列是用户名,第二列是密码,我需要一个命令来在用户输入他们的用户名和新密码时替换密码密码,这是我的密码

#!/bin/bash
#admin menu

#Register User
echo enter the username of the user you want to register.
read reguser
echo enter the password of the user you want to register.
read regpass

User_Pass="username_pass.txt"

if [ ! -e "$User_Pass" ]; 
then
echo "Creating Username and Passwords file"
touch $User_Pass
fi

echo "$reguser $regpass" | cat >> $User_Pass

echo user succesfully registered.

#Change Password
echo "Enter the username you want to change the password for"
read change1

change2=$(grep -q $change1 username_pass.txt)

if [ $change2=0 ];
then 
echo enter your new password

read newpass



awk -v newpass="$newpass" -v change1="$change1" '$1 ~ change1 {$2 = newpass}' username_pass.txt
#i tried this but it didnt work


    echo "password changed!"
else
    echo "no such username."
fi

【问题讨论】:

标签: bash passwords


【解决方案1】:

你可以使用sed

sed -i "s/$change1.*/$change1 $newpass/" username_pass

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2018-01-18
    • 1970-01-01
    • 2011-10-21
    相关资源
    最近更新 更多