PHP - Base64_encode() And Base64_decode()
I know why you shouldn't use base64_encode() to encrypt passwords, so please ...
I'm creating a membership based website. I've got a registration form that takes the password value then base64 encodes it, and puts the string value into a MySQL database. Now when the user goes to login he enters a username and a password. The password is base64_encoded() then this login form encoded password is compared to the encoded password in the MySQL database. However, the two strings are not the same, according to PHP. Does anyone know what is going on? Here's some code from the login form: Code: [Select] $user = $_POST['user']; $password = base64_encode($_POST['password']); $query = "SELECT * FROM users WHERE user_name = '$user' AND user_password = '$pass'"; $userstatsresult = mysql_query($query) or die ('Error in query: ' . mysql_error()); if (mysql_num_rows($userstatsresult)>0) { while($row = mysql_fetch_assoc($userstatsresult)) { if ($row[user_password] == $password) { echo 'Yay! They are the same!'; } else { echo 'WTF?'; } } } The output is always: WTF? I think that it has something to do with the interaction between MySQL and PHP because straight PHP works, as in: Code: [Select] // base64_encode('password') is 'cGFzc3dvcmQ=' if (base64_encode('password') == 'cGFzc3dvcmQ=') { echo 'They are equal strings!'; } else { echo 'They are NOT equal strings!'; } This will always output: They are equal strings! I'm really stuck here ... Similar TutorialsI want to encode a long string, and wish to make it shorter. base64_encode is very handy but it makes the string length longer. Is there an alternative to do the encoding/decoding with shorter encoded string length? Hi, I have a little code that checks if the user is logged in. Since I moved to another service it doesn't work anymore. Code: [Select] <?php // Start_session, check if user is logged in or not, and connect to the database all in one included file include_once("scripts/checkuserlog.php"); if (!isset($_SESSION['idx'])) { $msgToUser = '<br /><br /><font color="#FF0000">Only site members can do that</font><p><a href="register.php">Join Here</a></p>'; include_once 'msgToUser.php'; exit(); } else if ($logOptions_id != $_SESSION['id']) { $msgToUser = '<br /><br /><font color="#FF0000">Only site members can do that</font><p><a href="register.php">Join Here</a></p>'; include_once 'msgToUser.php'; exit(); } ?> Code: [Select] <?php if (isset($_SESSION['idx'])) { $decryptedID = base64_decode($_SESSION['idx']); $id_array = explode("p3h9xfn8sq03hs2234", $decryptedID); $logOptions_id = $id_array[1]; $logOptions_username = $_SESSION['username']; $logOptions_username = substr('' . $logOptions_username . '', 0, 15); ?> i try this code. Code: [Select] <video width="320" height="240" controls="controls" autobuffer="autobuffer"> <source src="data:video/mp4;base64,AAAA<?php echo chunk_split(base64_encode(trim(file_get_contents('kecak.mp4')))); ?>" type="video/mp4" /> Your browser does not support the video tag. </video> it's work when i play in Notebook(safari, firefox) but not work when i play on IPAD2(safari) or Samsung Galaxy(Opera). i think the problem is in Code: [Select] src="data:video/mp4;base64,AAAA<?php echo chunk_split(base64_encode(trim(file_get_contents('kecak.mp4')))); ?>because when i replace with Code: [Select] src="kecak.mp4"it's work at all device and browser. i must use base64_encode(trim(file_get_contents('kecak.mp4'))) because in real my case it's come from response from RESTFul to delivery video via http. string response from http same with base64_encode(trim(file_get_contents('kecak.mp4'))). thanks u for help :-) Hi, Since the latest versions of Access (2007/2010) it's possible to add attachments to rows. I have such a database with members and their photos, but i would like to export them (including photos) and use them for a new webapplication. I have made a XML-export with Access 2007. The photos which i have attached are encoded in the XML export. Please find below an example of the file smiley.jpg, which i have attached in a random row in my database. (The original file smiley.jpg you may find back he http://img812.imageshack.us/img812/8248/smileyq.jpg) XML-export generated by Access 2007 Code: [Select] <Foto> <FileData>FAAAAAEAAAAEAAAAagBwAGcAAAD/2P/gABBKRklGAAEBAQBkAGQAAP/bAEMAAwIC AwICAwMDAwQDAwQFCAUFBAQFCgcHBggMCgwMCwoLCw0OEhANDhEOCwsQFhARExQV FRUMDxcYFhQYEhQVFP/bAEMBAwQEBQQFCQUFCRQNCw0UFBQUFBQUFBQUFBQUFBQU FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFP/AABEIACgAKAMBIgAC EQEDEQH/xAAbAAACAgMBAAAAAAAAAAAAAAAABgUHAQgJA//EADIQAAIABAMFBgYC AwAAAAAAAAECAwQFEQAGEgcTFSExCBRRYYGRCSIkMkGxM3GCodH/xAAYAQADAQEA AAAAAAAAAAAAAAAEBQgHBv/EACgRAAIBAwMDBAIDAAAAAAAAAAECEQADBAUh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UnUzv0Uv +VuC5HkOg9fbBgxknTvp1o2bktczGuXRb4VmEfcAGPgEUdey7irCwJp6kZGDTpVJ eXQQ4SCwA/Z88GDBikbVpLKLatKFVRAA2AA4AH6pQSSZNf/Z </FileData> <FileName>smiley.jpg</FileName> <FileType>jpg</FileType> </Foto> It seems to be encoded with base64, but as soon as i try to decode it using the function base64_decode(), i don't get a valid output back. I have found some additional data back in the XSD-file, which is automatically generated when you make an XML-export in Access. There it seems to refer to base64, so i don't know what's going wrong. Code: [Select] <xsd:element name="FileData" minOccurs="0" od:jetType="oleobject" od:sqlSType="image"> <xsd:simpleType> <xsd:restriction base="xsd:base64Binary"> <xsd:maxLength value="1476395008"/> </xsd:restriction> </xsd:simpleType> </xsd:element> I have tried the following code, to get the image back ($data is filled with the encoded stuff from the XML-export): Code: [Select] <?php header('Content-Type: image/jpeg'); echo base64_decode($data); ?> I have looked on several websites, but i can't find a solution for this issue. The main goal is to export approx. 2500 members (with photos attached) from Access 2007. The data can be exported easily, but it's all about the photos which make it complicated. |