which is the best to use 'md5' or 'sha1'?
Possible to give a small example also?
Thanks Regards, X
PS: Problem im having is getting the 'md5/sha1' function to work so I can upload the output into to my database
which is the best to use 'md5' or 'sha1'?
Possible to give a small example also?
Thanks Regards, X
PS: Problem im having is getting the 'md5/sha1' function to work so I can upload the output into to my database
Quick summary: neither MD5 nor SHA1 is a good choice for password storage today. Both are fast, which makes brute‑force and GPU‑assisted attacks practical. Use PHP's built‑in password hashing API (password_hash and password_verify) so you get a slow, salted algorithm (bcrypt or Argon2 where available) and safe defaults.
Clarifying a couple of points from this thread: the variable used in techniner's sample (the $source name) is simply the plaintext password you want to hash — make sure it is actually set before calling the hash function. MD5 hex output is 32 characters; SHA1 hex output is 40 characters — pick a DB column length accordingly if you must store those. Also watch for simple PHP syntax problems (missing semicolons or uninitialized variables) and enable errors while debugging; a parse error will prevent any hashing from happening.
A minimal modern pattern (no manual salts) looks like this:
$hash = password_hash($password, PASSWORD_DEFAULT);
if (password_verify($attempt, $hash)) {
// password correct
} For database storage use a VARCHAR(255) (password_hash output is algorithm dependent), and always insert the hash via prepared statements / parameterized queries rather than string concatenation. If the hash functions appear "not working" when inserting to the DB, check: PHP error logs, the actual variable contents before the INSERT, the column size/type, and whether your DB call returned an error (expose and inspect exceptions during development).
Further reading: PHP manual on password_hash (for usage and available algorithms) and the OWASP Password Storage Cheat Sheet (best practices).
Jump to Post— techniner 2MD5.
Here is a sample for both:<?php $salt1="something custom"; $salt2="blahblah"; $salt3="differentblah"; $hash1=sha1($salt1.$source) $hash2=sha1($salt2.$source); $hash3=md5($salt3.$source); ?>
MD5.
Here is a sample for both:
<?php
$salt1="something custom";
$salt2="blahblah";
$salt3="differentblah";
$hash1=sha1($salt1.$source)
$hash2=sha1($salt2.$source);
$hash3=md5($salt3.$source);
?> difference between hash 1 and 2 (minus the semi colon)?
and what is the value of this $source?
I gather the output would be some hexadecimal value correct?
Thanks
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.