Valhalla Legends Archive

Programming => Web Development => Topic started by: hismajesty on December 22, 2003, 09:28 PM

Title: PHP-Encryption
Post by: hismajesty on December 22, 2003, 09:28 PM
Why does this generate errors?
Md5(crypt(base64_encode($password)))
Title: Re:PHP-Encryption
Post by: Spht on December 22, 2003, 09:32 PM
Quote from: hismajesty on December 22, 2003, 09:28 PM
Why does this generate errors?
Md5(crypt(base64_encode($password)))


I hope you're kidding.
Title: Re:PHP-Encryption
Post by: hismajesty on December 22, 2003, 09:36 PM
Quote from: Spht on December 22, 2003, 09:32 PM
Quote from: hismajesty on December 22, 2003, 09:28 PM
Why does this generate errors?
Md5(crypt(base64_encode($password)))


I hope you're kidding.

Sadly I'm not...I don't understand why encrypting something three ways would generate an error...
(It doesn't help that I'm just learning php either)
Title: Re:PHP-Encryption
Post by: Spht on December 22, 2003, 09:40 PM
Quote from: hismajesty on December 22, 2003, 09:36 PM
Quote from: Spht on December 22, 2003, 09:32 PM
Quote from: hismajesty on December 22, 2003, 09:28 PM
Why does this generate errors?
Md5(crypt(base64_encode($password)))


I hope you're kidding.

Sadly I'm not...I don't understand why encrypting something three ways would generate an error...
(It doesn't help that I'm just learning php either)

I don't know PHP. But that's like sayingMyReturn = MyFunction(DoesThis(AndThis(ToThis)))
Why doesn't this work???


You may need to post your Md5, crypt, base64_encode functions which could be buggy and causing the error.
Title: Re:PHP-Encryption
Post by: hismajesty on December 22, 2003, 09:42 PM
Those functions are all built into PHP. I guess I'll just do Md5($password) instead, I was just thinking that it being encrypted three times would make it more secure and what not.
Title: Re:PHP-Encryption
Post by: Spht on December 22, 2003, 09:44 PM
Quote from: hismajesty on December 22, 2003, 09:42 PM
Those functions are all built into PHP. I guess I'll just do Md5($password) instead, I was just thinking that it being encrypted three times would make it more secure and what not.

That works? Try:base64_encode($password)
crypt($password)
Md5($password)

Title: Re:PHP-Encryption
Post by: Banana fanna fo fanna on December 23, 2003, 10:02 AM
Ugh@spht

If you're looking for one-way encryption, pretty much the best you can get is double-SHA, that is, SHA the data once, then append a "session key" (if applicable) and hash again. If there are no such session keys, one time will suffice.
Title: Re:PHP-Encryption
Post by: Archangel. on December 25, 2003, 11:59 AM
hrm.

   <FORM>
      <INPUT TYPE=TEXT NAME=code VALUE="<?echo $code?>">
      <INPUT TYPE=SUBMIT NAME=action VALUE="Encode">
      <INPUT TYPE=SUBMIT NAME=action VALUE="Decode">
   </FORM><BR>
   <?
      if($action == "Encode") {
         echo "<B><FONT FACE=Arial>Output:</FONT></B><BR>";
         echo base64_encode($code);
      } elseif($action == "Decode") {
         echo "<B><FONT FACE=Arial>Output:</FONT></B><BR>";
         echo base64_decode($code);
      }
   ?>
Title: Re:PHP-Encryption
Post by: Yoni on December 25, 2003, 05:41 PM
Hash(Base64 of password) and Hash(Plaintext password) are equally secure. If all you're going to do is calculate a hash, encoding as base64 is unnecessary. See also St0rm's post.

Base64 by itself offers zero security. Its purpose is not security. Its purpose is to encode any data to a form that contains only printable characters, with an overhead of only 33% (as opposed to, for example, an overhead of 100% with encoding as Hex).
Title: Re:PHP-Encryption
Post by: hismajesty on December 25, 2003, 05:47 PM
Project, that was a pointless. We've already established that base64 was pointless; thus, the reason that I wasn't satisfied using just base64. Base64 is easily decoded with the base64_decode function of php; thus, it's a pointless form of encrypting. Anyways, I just decided to do MD5 hashing only.
Title: Re:PHP-Encryption
Post by: CrAzY on December 25, 2003, 05:48 PM
Quote from: ProjecT on December 25, 2003, 11:59 AM
hrm.

   <FORM>
      <INPUT TYPE=TEXT NAME=code VALUE="<?echo $code?>">
      <INPUT TYPE=SUBMIT NAME=action VALUE="Encode">
      <INPUT TYPE=SUBMIT NAME=action VALUE="Decode">
   </FORM><BR>
   <?
      if($action == "Encode") {
         echo "<B><FONT FACE=Arial>Output:</FONT></B><BR>";
         echo base64_encode($code);
      } elseif($action == "Decode") {
         echo "<B><FONT FACE=Arial>Output:</FONT></B><BR>";
         echo base64_decode($code);
      }
   ?>

Looks like a Visual Basic programmer.
Title: Re:PHP-Encryption
Post by: Archangel. on December 26, 2003, 06:56 PM
Uhhh sorry if it was to late... i just said my idea...
and Crazy a little Vb, cant do a nice work like you or other people, i still need to learn :o.
And Shadowed is teaching me php, heh, he is a god, he made Psi Ops.
Title: Re:PHP-Encryption
Post by: Arta on December 27, 2003, 05:04 PM
What are you trying to do exactly? If you're saving a password as a cookie or something, remember that in most cases, obtaining the hash of a password is equally as useful as obtaining the password itsself.

Hashing != Insta-secure.
Title: Re:PHP-Encryption
Post by: UserLoser. on December 27, 2003, 06:13 PM
Quote from: Spht on December 22, 2003, 09:40 PM
MyReturn = MyFunction(DoesThis(AndThis(ToThis)))
Why doesn't this work???

ROFL ;D
Title: Re:PHP-Encryption
Post by: Kp on December 27, 2003, 07:00 PM
Quote from: Arta[vL] on December 27, 2003, 05:04 PMWhat are you trying to do exactly? If you're saving a password as a cookie or something, remember that in most cases, obtaining the hash of a password is equally as useful as obtaining the password itsself.

Hashing != Insta-secure.

This depends in part on who he's trying to protect against.  If he's dubious about who else might be reading through the stored data, hashing the password server side is good enough if the intruder can only read saved data (cannot listen to your chat with the client).  Failure to do this is what got Trance (in part, anyway): the passwords were stored cleartext, and a malicious individual had read access to the password storage medium.  If the passwords had been stored as a hash, it would have taken at least a little bit of work for the attacker to determine Trance's password in cleartext form.

If the hash is computed client side, then, as you say, obtaining the hash is as good as having the password - for purposes of impersonating the user.  However, even in this case, having the hash of the password would not immediately grant knowledge of the user's cleartext password, so you could only impersonate him/her in this one location.

In my opinion, a good compromise between effort and security is to take the approach Blizzard uses -- a two layer hashing of the password, with the server remembering the one-pass hash and recomputing the two-pass hash from the stored data + the challenge/response cookies.
Title: Re:PHP-Encryption
Post by: UserLoser. on December 27, 2003, 08:36 PM
Quote from: Kp on December 27, 2003, 07:00 PM
This depends in part on who he's trying to protect against.  If he's dubious about who else might be reading through the stored data, hashing the password server side is good enough if the intruder can only read saved data (cannot listen to your chat with the client).  Failure to do this is what got Trance (in part, anyway): the passwords were stored cleartext, and a malicious individual had read access to the password storage medium.  If the passwords had been stored as a hash, it would have taken at least a little bit of work for the attacker to determine Trance's password in cleartext form.

If the hash is computed client side, then, as you say, obtaining the hash is as good as having the password - for purposes of impersonating the user.  However, even in this case, having the hash of the password would not immediately grant knowledge of the user's cleartext password, so you could only impersonate him/her in this one location.

In my opinion, a good compromise between effort and security is to take the approach Blizzard uses -- a two layer hashing of the password, with the server remembering the one-pass hash and recomputing the two-pass hash from the stored data + the challenge/response cookies.

How are the BotNet accounts & passwords saved?
Title: Re:PHP-Encryption
Post by: Kp on December 27, 2003, 08:53 PM
Quote from: UserLoser. on December 27, 2003, 08:36 PMHow are the BotNet accounts & passwords saved?

They're still saved however Skywing had them configured to be saved.  I haven't even touched his account modification functions (there's been no need).
Title: Re:PHP-Encryption
Post by: Adron on January 03, 2004, 05:42 PM

storedhash = read();
randomvalue1 = read();
password = recv();
hash = md5(password + randomvalue1);
for(i = 0; i < 1000000; i++)
  hash = md5(hash + randomvalue1);
if(storedhash == hash)
  success();


Very secure!
Title: Re:PHP-Encryption
Post by: UserLoser. on January 03, 2004, 06:37 PM
Quote from: Adron on January 03, 2004, 05:42 PM

storedhash = read();
randomvalue1 = read();
password = recv();
hash = md5(password + randomvalue1);
for(i = 0; i < 1000000; i++)
  hash = md5(hash + randomvalue1);
if(storedhash == hash)
  success();


Very secure!


Is there any language/scripting you don't know? :P
Title: Re:PHP-Encryption
Post by: Adron on January 03, 2004, 06:49 PM
Quote from: UserLoser. on January 03, 2004, 06:37 PM
Quote from: Adron on January 03, 2004, 05:42 PM

storedhash = read();
randomvalue1 = read();
password = recv();
hash = md5(password + randomvalue1);
for(i = 0; i < 1000000; i++)
  hash = md5(hash + randomvalue1);
if(storedhash == hash)
  success();


Very secure!


Is there any language/scripting you don't know? :P

That's probably not valid php btw... I've only done very little php scripting, and this was more like pseudocode. I was just suggesting that he hash it one million times for improved security.
Title: Re:PHP-Encryption
Post by: j0k3r on January 03, 2004, 09:31 PM
He missed an end if.

[edit]and an end for[/edit]
Title: Re:PHP-Encryption
Post by: dxoigmn on January 07, 2004, 02:29 PM
Quote from: j0k3r on January 03, 2004, 09:31 PM
He missed an end if.

[edit]and an end for[/edit]

He did?

Adron's code is fun.
Title: Re:PHP-Encryption
Post by: Adron on January 07, 2004, 04:14 PM
It's not the code that matters, it's the idea it tries to convey.
Title: Re:PHP-Encryption
Post by: dxoigmn on January 07, 2004, 05:52 PM
Quote from: Adron on January 07, 2004, 04:14 PM
It's not the code that matters, it's the idea it tries to convey.

That's why it's fun :)
Title: Re:PHP-Encryption
Post by: venox on October 31, 2004, 07:27 AM
Quote from: j0k3r on January 03, 2004, 09:31 PM
He missed an end if.

[edit]and an end for[/edit]

Actually, if you want to get technical, in PHP, if you are only doing 1 thing in an if/for statement the { } are not required, therefore..

if($blah)
   do_soemthing();

or

for($i = 0; $i > 10; $i++)
   do_something();

is just fine..