# De-crypting after using md5

**URL:** https://forum.kirupa.com/t/de-crypting-after-using-md5/29361
**Category:** programming
**Created:** [August 26, 2003, 12:31am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361 "2003-08-26T00:31:51Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![hamza84](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hamza84](https://forum.kirupa.com/u/hamza84)
#### Post date: [August 26, 2003, 12:31am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/1 "2003-08-26T00:31:51Z")

</div>

I was wondering how do you retrieve and decrypt something in MySQL after using md5. Thanks

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 12:43am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/2 "2003-08-26T00:43:47Z")

</div>

it’s technically impossible to decrypt an md5 hash 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 12:47am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/3 "2003-08-26T00:47:33Z")

</div>

Impossible to decrypt md5 there bro. Unless I’m out of the loop. If you want to check something against that value, here’s an example of some code that I use to validate user passwords. (passed using the post method from a form)

```php

$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) || (!$password)){
	echo "Please enter ALL of the information! <br />";
	include 'login_form.html';
	exit();
}
$password = md5($password);
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);

```

etc… check that mysql\_num\_rows has value, process data, etc…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 12:48am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/4 "2003-08-26T00:48:08Z")

</div>

add 1 to the posted at the same time column

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 1:24am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/5 "2003-08-26T01:24:41Z")

</div>

I did find this though  
[http://www.wiretapped.be/security/host-security/mdcrack/](http://www.wiretapped.be/security/host-security/mdcrack/)

Apparently, you can take an md5 hash and find a text string that will have the same collision as the original string since the number of varients is fixed at 2^128. But it is impossible to tell directly if the collision is indeed the origional string. Pretty cool actually.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 1:38am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/6 "2003-08-26T01:38:46Z")

</div>

lol. And i thought it was easy. Anyways, I asked that question cuz i have built this password retrieval thing for a website and when I tried it out, I was getting problems until I realized I was using md5 encryption. Oh well, thanks for the input anyways guys. I appreciate it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 1:44am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/7 "2003-08-26T01:44:34Z")

</div>

The easiest way would be to have a thing where you can reset the password with some randomly generated string, then set that string as the password and email it to them. Then they can log in and set it to what they want.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:02am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/8 "2003-08-26T03:02:02Z")

</div>

hmm, how come i never thought of that? Maybe cuz i don’t know how to generate a random password? hehe. Anyhow, could anybody help me out with this, plz?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:07am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/9 "2003-08-26T03:07:54Z")

</div>

not a prob. I’ll get you hooked up in a few

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:12am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/10 "2003-08-26T03:12:54Z")

</div>

```php
	function makeRandomPassword() {
  		$salt = "abchefghjkmnpqrstuvwxyz0123456789";
  		srand((double)microtime()*1000000); 
	  	$i = 0;
	  	while ($i <= 7) {
	    		$num = rand() % 33;
	    		$tmp = substr($salt, $num, 1);
	    		$pass = $pass . $tmp;
	    		$i++;
	  	}
	  	return $pass;
	}
	$random_password = makeRandomPassword();

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:19am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/11 "2003-08-26T03:19:57Z")

</div>

there are many ways to generate a random string… what i do is take the time and date, md5 that string and take the first 8 letters to make a random password. I email that to the user, and store the hash of that password in my database…

```php
<?php
function generatePSW ()
{
$longpsw = md5(date("l, F jS, Y g:i:d:s a")); 
$psw = substr ( $longpsw , 0, 8 );
return $psw;
}

$psw = generatePSW ();
echo("string to be mailed: <b>" . $psw);
echo("</b><<br>br>string to be stored in database: <b>" . md5($psw . "</b>"));
?>

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:24am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/12 "2003-08-26T03:24:23Z")

</div>

You guys have no idea how much i appreciate your help. Even a bear hug wont do it. Thanks a whole bunch guys. You rock!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:25am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/13 "2003-08-26T03:25:10Z")

</div>

hey, a hug would do 😛

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 26, 2003, 3:34am UTC](https://forum.kirupa.com/t/de-crypting-after-using-md5/29361/14 "2003-08-26T03:34:24Z")

</div>

Sure. _bear hug_ :thumb:
