473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

crypt with sha1?

Hi,

Does anybody now of a custom crypt function that implements sha1? The thing
I like about crypt is that I don't have to worry about (re)generating salt
when querying the database. Or are there perhaps other functions that
implements this same functionality and generates a sha1 hash?

Cheers.
Apr 15 '07 #1
2 3182

"amygdala" <no*****@noreply.comschreef in bericht
news:46**********************@news.kpnplanet.nl...
Hi,

Does anybody now of a custom crypt function that implements sha1? The
thing I like about crypt is that I don't have to worry about
(re)generating salt when querying the database. Or are there perhaps other
functions that implements this same functionality and generates a sha1
hash?

Cheers.
BTW: My system (localhost) implements md5. And I would rather not rely on a
future hosting server to have sha1 implemented.
Apr 15 '07 #2

"amygdala" <no*****@noreply.comschreef in bericht
news:46**********************@news.kpnplanet.nl...
Hi,

Does anybody now of a custom crypt function that implements sha1? The
thing I like about crypt is that I don't have to worry about
(re)generating salt when querying the database. Or are there perhaps other
functions that implements this same functionality and generates a sha1
hash?

Cheers.
Sorry, never mind, I found one at:
http://nl3.php.net/crypt
In one of the user comments.

From what I can tell, with my limited experience, it does the job
appropriately. If you beg to differ, please don't hold back.

Here's the code for those interested in it:

<?php

// NOTE: This function requires PHP 5.0.0 as we use "raw output" option of
sha1()
function sha1crypt($password, $salt=null) {
if ( (is_null($salt)) || (strlen($salt)<1) ) {
$salt='';
while(strlen($salt)<10) $salt.=chr(rand(64,126));
$salt='$sha1$'.$salt.'$';
}
if ($salt{0}!='$') return crypt($password, $salt);
$tmp=explode('$',$salt);
if ($tmp[1]!='sha1') return crypt($password, $salt);
$saltstr=$tmp[2];
if (strlen($saltstr) != 10) return crypt($password, $salt);
$encrypt=base64_encode(sha1($saltstr.$password,tru e));
return '$sha1$'.$saltstr.'$'.$encrypt;
}

// without salt, sha1crypt() will generate on
$pass=sha1crypt('foobar');
echo $pass."\n";

// pass directly password as salt - different output as password is not the
same
echo sha1crypt('foobarbaz',$pass)."\n";

// same password - same output
echo sha1crypt('foobar',$pass)."\n";

// Encrypt using MD5 passwords
echo sha1crypt('foobar','$1$blahblahg$')."\n";

?>
Apr 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: | last post by:
I'm curious how these two functions work together (when crypt() uses a md5 algo). Currently I know they will produce different output; is this due to the salt being used behind-the-scenes in md5()?...
2
by: Paul Fournier | last post by:
Just wondering, does anyone know if the crypt() function in PHP will always return a 34 character string if not salted? I want to encrypt my user's passwords into a database and I want to make...
3
by: Marco Herrn | last post by:
I want to use a crypt function to store crypted passwords. These will be used to verify mail-user access. Now the crypt() function from the module crypt is only significant for the first 8...
7
by: Bart Nessux | last post by:
Does Python have anything similar to Perl's Crypt::PasswdMD5??? I read about the crypt module... but it only does DES. Any plans to add md5 or other digests to it in the future?
0
by: AdrianK | last post by:
I'm having a lotta problems installing Crypt::RSA on Linux Linux gogol 2.4.17smt-mono using perl5.005_03. Main problem at present is that all the tests fail with Crypt::Primes When I run a trace...
0
by: John Bergstrom | last post by:
Hello everyone! I wrote a simple perl program to encrypt a string using Crypt::OpenSSL::RSA. Everything as described in the module documentation. The public key is a valid X.509 encrypted...
1
by: steve | last post by:
Hi, I have a set of passwords encrypted using perl’s crypt, from a perl forum being migrated to php. I like to bring them into php, and use them without changing them. How do I emulate perl’s...
7
by: Kenjis Kaan | last post by:
I would like to use the crypt function in a Win32 (ie. C program using Visual C++ 6.0 compiler). I wrote a little program to see if it will link but it didn't. So I guess maybe the function isn't...
0
by: Sri | last post by:
Hi I am trying to match a user password provided by a user on an ASP.NET web form with a Unix encrypted password stored in a Sybase database table. I know I cannot use MD5, SHA1, etc as the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.