Tell me more ×
IT Security Stack Exchange is a question and answer site for IT security professionals. It's 100% free, no registration required.

I am making a web app and I'm now stuck on making the login secure. I'm thinking of adding a salt to a user-inputted password and then hash it. (md5 or sha for example) and then I will reshuffle the results.

eg:

$salt = "hello";
$password = "password";
$newpassword = md5($salt.$password); //lets assume the result is 1234567890

I will reshuffle the order of the hash like exchanging the first and last character then 3rd and 3rd to the last.

the result will look like:

0284567391

Does this make the password more secure? Please don't suggest some hardcore encryption stuffs. I just need something that will make the passwords secure than just having them encrypted using a cracked hash algorithm.

share|improve this question
The short answer is no, this amounts to security by obscurity and adds no real security to your hashes. Also, don't use MD5, SHA or any general purpose hashing function. – Null Nov 29 '12 at 1:19
One needs to understand the implications of weaknesses found in hashing algorithms when it comes to protecting hashed passwords. While you could say MD5 is terribly broken, none of the currently feasible attacks on MD5 make cracking a hashed password any easier than it was before. – Null Nov 29 '12 at 1:23
@null how about this paper? crppit.epfl.ch/documentation/Hash_Function/Examples/… Does it sound feasible? Our presented algorithm allows us to find full MD5 collisions in only minutes on a 3Ghz Pentium4. – Salvador Dali Nov 29 '12 at 1:47
@null or may be these? win.tue.nl/hashclash/rogue-ca – Salvador Dali Nov 29 '12 at 1:48
@SalvadorDali You don't understand; these are chosen-prefix collision attacks. They are useless when you want to get the original password from a hash. For this, you'd need a preimage attack - which for MD5 is still in the order of 2^123.4, something that would take more than the age of the universe to complete, ie: unfeasible. – Null Nov 29 '12 at 1:51
show 1 more comment

migrated from stackoverflow.com Nov 29 '12 at 1:20

6 Answers

The "shuffling" you intend is conceptually a kind of encryption: you apply a secret convention on the result. This changes anything to the security only if the convention is indeed kept away from the prying eyes of the attacker -- the attacker who just plundered the database of hashed passwords, and thus had some extensive access to the internals of your server. But the server must know of the shuffling (since it applies it). Therefore, it seems rather improbable that your shuffling is unknown to the attacker. Conclusion: your shuffling is probably not useful.

What would increase security would be to use a proper password-hashing function, which includes a salt in a cryptographically sane way, and is adequately slow (i.e. made very slow through thousands or even millions of iterations). This is called bcrypt. This sort of thing must not be improvised; homegrown schemes are very rarely secure (most are deemed secure by their inventor, but reality has a tendency to be unkind to the dreams of the self-made inventors, especially in highly technical areas where success cannot be tested, in particular cryptography).

share|improve this answer

To make your password storage safe, you should not use MD5 or any other fast hash algorithm, instead use a key derivation function like BCrypt.

The problem with fast algorithms is, that you can calculate 8 Giga MD5-hashes per second with common hardware (in 2012). That makes it possible to brute-force a whole english dictionary with about 500000 words, in less than a millisecond!

With shuffling the resulting hash-value, you add an additional secret to the hash. This secret will increase security just as long, as it stays secret. As long as the attacker only got access to the database (SQL-injection) it can help, as soon as the attacker gains control over the server (and your code) there is no benefit at all. You could achieve the same easier by adding a pepper to the password before hashing.

BCrypt was especially designed to hash passwords, and is therefore slow (needs some computing time). With a cost factor you can adapt the needed time to future (and therefore faster) hardware.

Using BCrypt can be as easy, as using the MD5 hash function. PHP 5.5 will have it's own functions password_hash() and password_verify() ready, to simplify this task. There is also a compatibility pack for PHP 5.3/5.4 available, downloadable at password_compat.

share|improve this answer

If you're looking for "more secure," you should use Blowfish or similar using the crypt(); function.

Swapping values should make a simple hash like md5 more secure, but assuming someone has already stolen your hashes, who is to say they don't already know that your application swaps characters in the hash? They would then un-shuffle your hashes and break them easily (assuming a hash like sha1 or md5) with an online tool.

tl;dr, use crypt(); instead and pick good algo and salts.

share|improve this answer
2  
You really mean bcrypt, a hashing function built on Blowfish (but it isn't really Blowfish, which is a symmetric block cipher). – Null Nov 29 '12 at 1:26
Perhaps I am missing something - can crypt not run as blowfish on most machines? (below from php.net) CRYPT_BLOWFISH - Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", a two digit cost parameter, "$", and 22 digits from the alphabet "./0-9A-Za-z". – Enjoys Turtles Nov 29 '12 at 18:13
That's a bit of misnomer. If you pay close attention, the manual goes on to say it's a "Blowfish-based hashing algorithm" – Null Nov 29 '12 at 19:24
Ah, thanks for clearing that up! – Enjoys Turtles Nov 29 '12 at 20:41

I'm gonna make this one short and sweet.

First, check this link out: http://crackstation.net/hashing-security.htm

Second, just use PBKDF2/bcrypt and a long salt. You'll be safe with that. Engineering your own type of manipulation, encryption, or hashing is almost never a good idea.

share|improve this answer

First of all stop using md5 as hash function for hashing passwords. Nevertheless it is not broken, but it suffers from variety of weaknesses. Use SHA-2 instead.

Regarding the reshuffling part - not at all. This is security by obscurity. It just make it a little bit more complicated, but it does not provide any additional security. BTW this branch is more applicable for such questions http://security.stackexchange.com/

P.S before blindly putting an -1, think about justifications. For my answer I have found at least one: - Is SHA1 better than md5 only because it generates a hash of 160 bits?

share|improve this answer
-1 For recommending the use of SHA-anything for hashing passwords. – Null Nov 29 '12 at 1:17
Are there any justification or you just do not like SHA-anything. Any reply to this post ? security.stackexchange.com/questions/19705/… – Salvador Dali Nov 29 '12 at 1:32
3  
The SHA family is a family of general purpose hashing functions. This means they're fast, which is bad when you're hashing passwords. To protect passwords you want the hashing function be as slow as possible (without hurting user experience too much). That's why you need a function with configurable slowness, like bcrypt or PBKDF2 – Null Nov 29 '12 at 1:45
1  
(read Thomas Pornin's answer) – Null Nov 29 '12 at 1:52
@null, yes, I am sorry. For some reason I thought that I need to add a prefix only for one of the original messages. And because of this started this misunderstanding. Here -1 is well deserved. One more time sorry – Salvador Dali Nov 29 '12 at 2:04
show 1 more comment

Why not just use SHA1 or SHA255?

share|improve this answer
-1 Because you should never use a general purpose hashing function like SHA to hash passwords. – Null Nov 29 '12 at 1:16
SHA1 has been cracked and i need something more secure than just having it hashed directly. – Gpoy Gwapo Nov 29 '12 at 1:17
1  
Cracked is not really the correct word. But you shouldn't be using SHA-x to hash passwords – Lucas Kauffman Nov 29 '12 at 7:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.