LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-08-2016, 06:27 AM   #1
kvr123
LQ Newbie
 
Registered: Dec 2016
Posts: 4

Rep: Reputation: Disabled
Pass generator question


Im trying to make a bash script that will ask the name of the user, favorite food and the current date and save these to the variables food, date and name a random password will then be generated. When the user forgets the password all he has to do is enter the same name (userrecovery), favorite food (foodrecovery) and the date (daterecovery) when the password was generated and the password should be shown. The code i use to generate a random password:

Code:
choose() { echo ${1:RANDOM%${#1}:1} $RANDOM; }
  pass="$({ choose '!@#$%^\&'
   choose '0123456789'
   choose 'abcdefghijklmnopqrstuvwxyz'
   choose 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
   for i in $( seq 1 $(( 4 + RANDOM % 8 )) )
      do
         choose '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
      done
  } | sort -R | awk '{printf "%s",$1}')"
I tried something like:

Code:
if [ $food=$foodrecovery -a $date=$daterecovery -a.... ]
   echo $pass
This works but when i close the script and reopen it will generate a new password which it shouldnt.
 
Old 12-08-2016, 07:00 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,833

Rep: Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970Reputation: 5970
How are you storing/retrieving your data?

Who is going to remember when a password was generated?
 
Old 12-08-2016, 09:55 PM   #3
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Rep: Reputation: 51
I'm not very bash literate, but it doesn't look like you're seeding RANDOM anywhere in there. I assume that's a necessary step.
 
Old 12-09-2016, 08:54 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Yep, you're going to need to save that in a DB of some kind that BASH can read later on.
Where are you calling the function to generate a new key?
Maybe have a line in there somewhere to test if one is already created then do not create another one.

I am not an expert, but logically that sounds sound. It is hard to see why you are having this problem only seeing two snippets of your code.
 
  


Reply

Tags
bash, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pass _server variable to html and a question about a condition latino Programming 2 12-21-2010 04:32 PM
[SOLVED] Question about Eric Hameleers' firewall generator Switch7 Slackware 6 11-26-2009 07:06 AM
c++ pass-by-value question kpachopoulos Programming 1 05-19-2009 09:51 AM
function, pass by reference question true_atlantis Programming 5 04-02-2004 11:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration