Web Design and Web Development Forum

  1. #1
    Join Date
    Feb 2005
    Location
    Moodles, UK
    Posts
    2,258
    Rep Power
    0
  2. Calamitie will become famous soon enough
  3. Question Why base64?

    Hi,

    I am making a new website which will highly depend on secure database entries, and somebody suggested to use base64 (base64_encode/decode) in PHP and it works great and I thought it was secure.

    After thinking about it, I couldn't understand the point of base64 at all - if somebody got into the database, even though selecting the tables would just send 'gibberish' base64, they could easily decode the base64 either with their own script or a simple Google search!

    So that lead me to ask what is the point of base64 when it can be decoded just as easily as it was encoded?

    No doubt a really simple answer will come out of my question, but I thought i'd ask anyway considering I couldn't find any info. on Google (!).

    Thanks in advance,

    Michael McNeela (Calamitie)
    Reply With Quote Reply With Quote
  4. #2
    f1do's Avatar
    Join Date
    May 2005
    Age
    24
    Posts
    117
    Rep Power
    8
  5. f1do is on a distinguished road
  6. Re: Why base64?

    What you are probably looking for is hashing not encoding/decoding. When you hash a string it makes it imposible to turn it back to the original. But when you encode the same string two different times it returns the same string. The most used PHP hashing function is probably md5(), theres also sha1() and I cant remember any others.
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    Feb 2005
    Location
    Moodles, UK
    Posts
    2,258
    Rep Power
    0
  8. Calamitie will become famous soon enough
  9. Re: Why base64?

    Thanks for your reply.

    I was thinking about using MD5 for the database aspects, but I still wonder what would be the uses of base64 encoding, as I have seen it used alot; but like I said, I can't see how it could add security!
    Reply With Quote Reply With Quote
  10. #4
    Join Date
    Dec 2004
    Posts
    562
    Rep Power
    8
  11. eddmun is on a distinguished road
  12. Re: Why base64?

    Base64 is used a lot for encoding files into something that can be stored in a database field. For example, you could take an image which has been uploaded to the server Base64-encode it and store it in a database.

    Later on you could write a script that you Base64-decode that database entry and display it to the user as an image again. If you tr and put the normal contents of an image file in a query it won't work easily.

    I don't think there are any security applications for it, unless you can apply a salt to it?
    Reply With Quote Reply With Quote
  13. #5
    unclekyky's Avatar
    Join Date
    Sep 2004
    Age
    22
    Posts
    5,184
    Rep Power
    13
  14. unclekyky is on a distinguished road
  15. Re: Why base64?

    All base64 does is turn the data into some printable ASCII. It should almost never be used in security.
    Spore-Game - The Ultimate Spore Fan-Site
    Abnegating Avunculicide Since 1601 | YC Wiki - "Quidquid latine dictum sit, altum sonatur."
    Reply With Quote Reply With Quote
  16. #6
    Join Date
    Feb 2005
    Location
    Moodles, UK
    Posts
    2,258
    Rep Power
    0
  17. Calamitie will become famous soon enough
  18. Re: Why base64?

    Oh ok, that clears up alot of questions I had...

    Basically, I am making a website which will work like 'Piczo' (but better) and I just want to make sure that people's hard work and effort doesn't get lost for the sake of me not protecting the database and generally the entire website.

    I think I will use MD5 for passwords, but then that means that I can't recover people's passwords (just generate a new, random one).

    If anyone might be able to help i'd be very greatful.

    Thanks in advance,

    Michael McNeela (Calamitie)
    Reply With Quote Reply With Quote
  19. #7
    Join Date
    Jun 2005
    Location
    California, USA
    Age
    22
    Posts
    2,821
    Rep Power
    0
  20. Mau is on a distinguished road
  21. Re: Why base64?

    If you hash passwords, there is no realistic way to recover them, however it still remains the best solution. To recover a password, you would want to generate a new random one.
    Reply With Quote Reply With Quote
  22. #8
    Join Date
    Mar 2006
    Location
    Toronto, Ontario
    Posts
    2,270
    Rep Power
    9
  23. Nick Presta is on a distinguished road
  24. Re: Why base64?

    Yes, to "recover" a password, you would create a new one and send the email to the user. Another way would be to create a temporary secure string/etc and email it to the user. Then, using that string in the query string, if it matches the field in the database for the username, let the user create a new password themselves and update the password field.

    I would suggest using SHA1 over MD5 but it's totally up to you and it won't make a huge difference either.
    Reply With Quote Reply With Quote
  25. #9
    Join Date
    Jul 2005
    Location
    Cambridgeshire, UK
    Posts
    151
    Rep Power
    7
  26. Orry Verducci is on a distinguished road
  27. Re: Why base64?

    It is generally recommended that passwords be hashed, and random ones generated when forgot (which a lot a sites do probably because they are hashed). In reality if someone were to hack the database and get the hashes, they could use MD5 dictionary sites which basically gather a list of what MD5's match what words, but that is where users are recommended to use numbers, different cases or in many cases, a password that isn't even a real word.
    Reply With Quote Reply With Quote
  28. #10
    Join Date
    Dec 2004
    Posts
    562
    Rep Power
    8
  29. eddmun is on a distinguished road
  30. Re: Why base64?

    SHA1 has been broken I think, so use MD5.
    Reply With Quote Reply With Quote