sha1 question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sha1 question
# 1  
Old 03-05-2011
sha1 question

What is the unix shell scripting equivalent of the following php code? I have tried to reproduce it, but I haven't been able to.

Code:
<?php
sha1(sha1(strtolower($user) . $pass) . $sessionid);
?>


Last edited by radoulov; 03-05-2011 at 05:43 PM.. Reason: Code tags!
# 2  
Old 03-05-2011
What OS and shell are you using?
# 3  
Old 03-05-2011
I use ubuntu linux.
# 4  
Old 03-05-2011
The latest Ubuntu uses bash4, so you could use something like this:

Code:
$ user=MyUser pass=mypass sessionid=mysessionid
$ _sha1=$(sha1sum <<< "$(sha1sum <<< "${user,,}$pass")$sessionid")
$ printf '%s\n' ${_sha1% *}
91aacc49855185f87659ffd87b8b4944c4822412

# 5  
Old 03-05-2011
These two scripts don't seem to match, so I don't know what I have done wrong.

Code:
<?php
$sessionid='mysessionid';
$user='myuser';
$pass='mypass';
$_sha = sha1(sha1(strtolower($user) . $pass) . $sessionid);
echo "$sha_pass\n";
?>

Code:
user="myuser"
pass="mypass"
sessionid="mysessionid"
_sha1=$(sha1sum <<< "$(sha1sum <<< "${user,,}$pass")$sessionid")
echo $_sha1

test:
laptop:~$ printf '%s\n' ${_sha1% *}
bf281edee15d125685d4a26f9542e9d1103aa218
laptop:~$ php shapass.php
27fe0e704617028883596d167f151d5a1a189dbd
# 6  
Old 03-05-2011
My sh script version agrees with the php version. Also, while I'm not very familiar with bash 4, it seems to me that the outermost pair of double quotes is off (the pair cross a command substitution boundary).

Code:
$ printf %s%s $(printf %s%s "$(printf %s MyUser | tr '[:upper:]' '[:lower:]')" mypass | openssl sha1) mysessionid | openssl sha1

27fe0e704617028883596d167f151d5a1a189dbd

Regards,
Alister

---------- Post updated at 05:33 PM ---------- Previous update was at 05:30 PM ----------

Woops! Disregard my comment regarding the quoting in the bash 4 code. I misread it. Smilie

Last edited by alister; 03-05-2011 at 06:45 PM..
# 7  
Old 03-05-2011
thanks

this works! thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. OS X (Apple)

SHA1 verification script

Hi guys! Me again! ... I'm trying to build (on MacOS directly) a bash script that will help me verify a SHA1 digest (to verify downloads and so on and so forth). So first off, here's my version of BASH under OSX: bash-4.4$ And here's my version of Sierra (macOS): 10.12.3 (16D32) ... (2 Replies)
Discussion started by: Ardzii
2 Replies

2. Programming

SHA1 hash calculation

hi i want to generate SHA1 hash of string in Linux (atmark) and downloaded the XYSSL-0.9 version code for the same.i have the algorithm which takes file as argument and returns hash of file . And of same file while I generated the key using online tools then it doesn't match with my compiled... (4 Replies)
Discussion started by: ahsaas42
4 Replies

3. UNIX Desktop Questions & Answers

Please Help me out with this question

. Make a new copy of mars.txt called marsx. What happens if you give the following commands when the files bio and marsx both already exist? Don't guess, try it! a) cp bio marsx b) mv bio marsx (2 Replies)
Discussion started by: rohit.katpalli
2 Replies

4. Shell Programming and Scripting

parse csv file, sha1 hash and output

I have a file, not really a csv, but containing delineated data just the same. Lets call that file "raw_data.txt". It contains data in the format of company name:fein number like this: first company name:123456789 second company name:987654321 what i need to do is read this file, apply... (11 Replies)
Discussion started by: FreddyG
11 Replies

5. UNIX for Dummies Questions & Answers

Question

I need to write a script file that will tell me the largest number in a group of numbers. ANy help is greatly appreciated (2 Replies)
Discussion started by: twan
2 Replies

6. UNIX for Dummies Questions & Answers

got a question

on of the question that I have is that in class . We were asked this question **What command would you use to list the last modification time of all files in /tmp whose filenames end in exactly two digits? I know that we need to to ls /tmp/ ??.... but I did not know how to find that last... (2 Replies)
Discussion started by: xzyan
2 Replies

7. UNIX for Dummies Questions & Answers

X Question

Hello, I've posted this in an X group, but I thought one of you might be able to help. I'm a novice programmer and I'm trying to write an X program in which pressing a button will launch another program. I know the syntax is something like "(Widget) -command {exec /usr/X11R6/bin/xcalc &}"... (5 Replies)
Discussion started by: af6
5 Replies

8. Shell Programming and Scripting

Question

when the user selects an option ou from the list how is it possible to let the script detect the option and carry out the appropriate action...i noe its suppose to use the for or if loop..but how ?? (3 Replies)
Discussion started by: MaRk2002
3 Replies

9. Programming

Question !

Hi a am writing a C Programe on Vi Editor (File Handelling),and i am compiling it using fcc but it not compiling ,Even Vi not saving my file.Tell me how can i do that.One More Thing I want to know that ,Is their any subsitute of conio.h. (3 Replies)
Discussion started by: at_renai2001
3 Replies
Login or Register to Ask a Question