username, password program in bash -


i have program asks input user on username , password stores in text file column 1 usernames , column 2 passwords, need command replaces password when user inputs username , new password, heres have

#!/bin/bash #admin menu  #register user echo enter username of user want register. read reguser echo enter password of user want register. read regpass  user_pass="username_pass.txt"  if [ ! -e "$user_pass" ];  echo "creating username , passwords file" touch $user_pass fi  echo "$reguser $regpass" | cat >> $user_pass  echo user succesfully registered.  #change password echo "enter username want change password for" read change1  change2=$(grep -q $change1 username_pass.txt)  if [ $change2=0 ];  echo enter new password  read newpass    awk -v newpass="$newpass" -v change1="$change1" '$1 ~ change1 {$2 = newpass}' username_pass.txt #i tried didnt work       echo "password changed!" else     echo "no such username." fi 

you can use sed

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

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -