PHP - Add Md5 Hash To Post Code
what would be the correct way to add an MD5 has to the following POST code?
$_POST['pass'] = mysql_real_escape_string($_POST ['pass']); '".$_POST ['pass']."', thanks in advance! Similar TutorialsI have some data that the user can search by using their post code. I want to results to be relevant to the users postcode. For example the user can search through local events by their post code and I want to data returned to be near their postcode. So if the user looks for events near Manchester I want it to return the surround area e.g Manchester, Leeds etc. Although I think for this I'm going to need some kind of algorithm. Has anyone done something like this in the past and could point me in the right direction? Thanks for any help. Hello together, I'm still relatively new with PHP and I'm encountering an error with the error code (Warning: Undefined array key "title" in I:\xampp\htdocs\test\Datenspeichern.php on line 13 to 17.). Normally I wanted that when I enter the data in the fields from the CD_Website page, that it is inserted in my created database and displayed in the table on the page. Does anyone know where my error is? Thanks a lot
main Code= <!doctype html> <html> <head> <meta charset="utf-8"> <title>Unbenanntes Dokument</title> <style type="text/css"> table { border-collaps: collapse; width: 100%; font-family: serif; font-size: 35px; text-align: center; } td { font-size: 25px; text-align: center; font-family: serif; } </style> </head> <body> <table> <tr> <th>CD-Titel</th> <th>Artist</th> <th>Songtitel</th> <th>Musiklänge</th> <th>Lied Nummer</th> </tr> <?php $host = "localhost"; $user = "root"; $password = ""; $db_name = "cdaufgabe"; $con = mysqli_connect($host, $user, $password, $db_name); if(mysqli_connect_error()) { die("Verbindungsabbruch mit der Datenbank: ". mysqli_connect_error()); }; $check = "SELECT * FROM `cd-titel`"; $result = mysqli_query($con, $check); if ($result > null) { while ($row = $result->fetch_assoc()){ echo "<tr><td>" . $row['CD-Titel'] . "</td> <td>" . $row['Artist'] . "</td> <td>" . $row['Songtitel'] . "</td> <td>" . $row['Musiklänge'] . "</td> <td>" . $row['Lied-Nummer'] . "</td></tr>"; }; }; /*if (isset($_POST['submitted'])) { $titel = $_POST['titel']; $artist = $_POST['artist']; $songtitel = $_POST['songtitel']; $musicle = $_POST['musicle']; $liednr = $_POST['liednr']; $data_add = "INSERT INTO cd-titel (CD-Titel, Artist, Songtitel, Musiklänge, Lied-Nummer) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; if (!mysqli_query($db_name, $data_add)) { die('Fehler beim einfügen von Daten'); } } */ // $data_add = "INSERT INTO `cd-titel` (`CD-Titel`, `Artist`, `Songtitel`, `Musiklänge`, `Lied-Nummer`) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; // mysqli_query($con, $data_add); /*mysqli_query($con, $data_add);*/ ?> <form methode="post" action="Datenspeichern.php"> <input type="text" name="titel" placeholder="CD-Titel"/> <input type="text" name="artist" placeholder="Artist"/> <input type="text" name="songtitel" placeholder="Songtitel"/> <input type="text" name="musicle" placeholder="Musiklänge"/> <input type="text" name="liednr" placeholder="Lied-Nummer"/> <input type="submit" name="submitted" value="speichern"/> </form> </br></br></br> </table> </body> </html> second code(Datenspeichern.php)= <?php $con = mysqli_connect('localhost', 'root', ''); if (!$con) { echo'Nicht verfügbar'; } if (!mysqli_select_db($con, 'cdaufgabe')){ echo 'Datenbank nicht ausgewählt'; }; $titel = $_POST['titel']; $artist = $_POST['artist']; $songtitel = $_POST['songtitel']; $musicle = $_POST['musicle']; $liednr = $_POST['liednr']; $data_add = "INSERT INTO cd-titel (CD-Titel, Artist, Songtitel, Musiklänge, Lied-Nummer) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; if (!mysqli_query($con, $data_add)){ echo 'Fehler'; } else { echo'Eingefügt'; }; header("url=CD_Webseite.php"); ?> Does anyone knows the mistake i keep doing? Rules: 1) It has to be legit and actually work and have a useful function in society/web world. 2) The code cannot be minimized into one line. It has to have line breaks. (Not necessarily for each new function or short hand property, but so it's partly readable) 3) It has to be written in PHP or Javascript. For example, (Not my original code) but I'll start: A time_ago function: function timeago($tm,$rcs = 0) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x = sprintf("%d %s ",$no,$pds[$v]); if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm); return $x; }Your turn! Edited by Monkuar, 24 January 2015 - 05:06 PM. Hey guys, First post here, so feel free to flame me if im violating the rules somehow. So, the issue is this: i built an ebay listing creator for a customer. it conssists of a form with several fields being posted to a page that assembles everything into a listing (text, images, radio buttons etc.). now, what i want to do is to easily allow the customer to copy the compiled source code into the clipboard (or a txt file, doesnt really matters) - in order to easily copy it into ebay. I tried it with CURL, but all i get is the source without the posted information. I must be missing something there. Any help would be appreciated, if you need links or codes iv's used, ill provide. Thanks in advance! <?php query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul class="rpul"> <li> <div class="class="post-thumb wp-post-image" style=' '> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </div><div class='cat-post-text'> <h1> <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
Guys, Having a major headache here. I need to send an enquiry using jquery and php. The user can only send an enquiry if they are logged in - so it's a one click process. On the click (which is an <a> tag) the user's data is retrieved from the database and sent to the company they are enquiring about. When the link is clicked, a jquery popup is shown to notify the user that the enquiry has been sent. This all works. However, currently the enquiry is sent when the page loads and this is what I'm having trouble with. Code: [Select] <a href="#e" onclick="openinfobox('Enquiry Sent', 1)" class="enq"></a>What I want to do is say if the URL contains #e, then send the enquiry, otherwise do nothing. I understand that the # portion of the url cannot be referenced by PHP. How on earth can I run php process to say only run this php process if there is a # in the url? I have a section on my website where the url points to www.example.com/some_page#some_element #some_element is used by javascript to load the element in question into the parent element. However i need pagination done on this loaded element. How should i go about it? would it work? obv i cant use www.example.com/some_page#some_element/page/2. Any tips or advice? Is a hash array the same thing as an associative array? My PHP books make no reference to this, yet I have seen the term referred to. Thanks. Are there any PHP hashes that are extremely secure and that CANNOT be reverse-engineered?
Hi SMF forum use semi-colom in url for example http://www.phpfreaks.com/forums/profile/?area=showposts;u=71740 after showposts there is semi-colon. Sometimes use hash(#) how can i do this with superglobal $_GET??? Hello, I created a system where emails get encrypted with a random key that gets stored in a database, what are the odds of the Hashes Colliding? Part of the code: function genRandomString($num) { $length = $num; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } $Key=genRandomString(10); $email_s=hash_hmac('ripemd160', $email, $Key); Thankyou, GB. I have a login system Username and Password.
My password is encrypted with bcrypt, if it okay to store that bcrypt in a session as $_SESSION["hash"]
To verify that the user is who they say they are?
Or do i only need to do
$_SESSION["username"]
Trying to echo a string that contains a hash symbol. Instead of getting a hash symbol, I get %29. The code I am using is pretty basic -->$idx="#" . $idxA;<--, but as stated, when I echo $idx, it comes out as %29. (All of this is part of a form, get, attempting to pass a bookmark to the receiving program. Thoughts? Hi,
Recently I've been trying writing a safe password hash and I wanted to know that if I use an MD5 hash at the end, just so it will be like some short of "packed",so instead of saving a 128 string, I'll use md5 to "pack" it into 32 characters and save up to 96 characters.
I know MD5 isn't safe and all, but the question is, does it lower the security ?
Also, would be happy for feedbacks about my password hash
function hash_($input,$key) { $op=hash("whirlpool",hash("sha512",$key) . "$" . $input . "$" . hash("sha512",$key)); Hi,
I am trying to get this script to execute as an administrator of an online system. If a user has forgotten their password, I enter their username and enter a new password which they can update later. I am not sure why this is not updating the password for the username entered?
<?php // Initialize the session session_start(); // Check if the user is logged in, if not then redirect to login page if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){ header("location: login.php"); exit; } // Include config file require_once "config.php"; // Define variables and initialize with empty values $new_password = $confirm_password = ""; $new_password_err = $confirm_password_err = ""; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Validate new password if(empty(trim($_POST["new_password"]))){ $new_password_err = "Please enter the new password."; } elseif(strlen(trim($_POST["new_password"])) < 6){ $new_password_err = "Password must have atleast 6 characters."; } else{ $new_password = trim($_POST["new_password"]); } // Validate confirm password if(empty(trim($_POST["confirm_password"]))){ $confirm_password_err = "Please confirm the password."; } else{ $confirm_password = trim($_POST["confirm_password"]); if(empty($new_password_err) && ($new_password != $confirm_password)){ $confirm_password_err = "Password did not match."; } } // Check input errors before updating the database if(empty($new_password_err) && empty($confirm_password_err)){ // Prepare an update statement $sql = "UPDATE User_Accounts_ SET password = ? WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "ss", $param_password, $username); // Set parameters $param_password = password_hash($new_password, PASSWORD_DEFAULT); $username = $_POST['username']; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Password updated successfully. Destroy the session, and redirect to login page session_destroy(); header("location: login.php"); exit(); } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($link); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Reset Password</title> <style type="text/css"> body{ font: 14px sans-serif; } .wrapper{ width: 350px; padding: 20px; } </style> </head> <body> <div class="wrapper"> <h2>Reset Password</h2> <p>Please fill out this form to reset your password.</p> <p><strong>Username</strong> <input type="text" name="username" class="form-control"> </p> <p> </p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <div class="form-group <?php echo (!empty($new_password_err)) ? 'has-error' : ''; ?>"> <label>New Password</label> <input type="password" name="new_password" class="form-control" value="<?php echo $new_password; ?>"> <span class="help-block"><?php echo $new_password_err; ?></span> </div> <div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>"> <label>Confirm Password</label> <input type="password" name="confirm_password" class="form-control"> <span class="help-block"><?php echo $confirm_password_err; ?></span> </div> <div class="form-group"> <input type="submit" class="btn btn-primary" value="Submit"> <a class="btn btn-link" href="welcome.php">Cancel</a> </div> </form> </div> </body> </html>
When a User changes his/her Email Address, should I generate a new Salt and Hash? (I am re-using the code I used for a Password Reset, and during that I generated a new Salt and Hash for security. I guess it can't hurt...) Thanks, Debbie HI, I have a registration script where a password is made with one hash, and a user password reset page that uses another hash. I don't know how to make them the same, as every time I change them, it messes up the code and I get errors. I will comment the parts that I think need changing. Because when I try to log in with the new password that was made by the reset password script, it says "wrong username or password" because either it wasn't updated in the database, or it was updated in a bad way. Any help greatly appreciated. The password email reset code: Code: [Select] <?php define('IN_SCRIPT', true); // Start a session session_start(); ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = ""; $database = ""; $username = ""; $password = ""; $tbl_name = ""; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); echo "connected to database!!"; } else { echo "failed to select database"; } //this function will display error messages in alert boxes, used for login forms so if a field is invalid it will still keep the info //use error('foobar'); function error($msg) { ?> <html> <head> <script language="JavaScript"> <!-- alert("<?=$msg?>"); history.back(); //--> </script> </head> <body> </body> </html> <? exit; } //This functions checks and makes sure the email address that is being added to database is valid in format. function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } if (isset($_POST['submit'])) { if ($_POST['forgotpassword']=='') { error('Please Fill in Email.'); } if(get_magic_quotes_gpc()) { $forgotpassword = htmlspecialchars(stripslashes($_POST['forgotpassword'])); } else { $forgotpassword = htmlspecialchars($_POST['forgotpassword']); } //Make sure it's a valid email address, last thing we want is some sort of exploit! if (!check_email_address($_POST['forgotpassword'])) { error('Email Not Valid - Must be in format of name@domain.tld'); } // Lets see if the email exists $sql = "SELECT COUNT(*) FROM users WHERE email = '$forgotpassword'"; $result = mysql_query($sql)or die('Could not find member: ' . mysql_error()); if (!mysql_result($result,0,0)>0) { error('Email Not Found!'); } //Generate a RANDOM MD5 Hash for a password//THIS IS THE POSSIBLE PROBLEM $random_password=md5(uniqid(rand())); //Take the first 8 digits and use them as the password we intend to email the user $emailpassword=substr($random_password, 0, 8); //Encrypt $emailpassword in MD5 format for the database $newpassword = md5($emailpassword); // Make a safe query $newpassword = mysql_real_escape_string($newpassword); $query = sprintf("UPDATE 'users' SET 'password' = '$newpassword' WHERE 'email' = '$forgotpassword'"); //Email out the infromation $site_name = "mysite.COM"; $site_email = "noreply@mysite.COM"; $subject = "Your New Password"; $message = "Your new password is as follows: ---------------------------- Password: $emailpassword ---------------------------- Please make note this information has been encrypted into our database This email was automatically generated."; if(!mail($forgotpassword, $subject, $message, "FROM: $site_name <$site_email>")){ die ("Sending Email Failed, Please Contact Site Admin! ($site_email)"); }else{ error('New Password Sent!.'); } } else { ?> <form name="forgotpasswordform" action="" method="post"> <table border="0" cellspacing="0" cellpadding="3" width="100%"> <caption> <div>Forgot Password</div> </caption> <tr> <td>Email Address:</td> <td><input name="forgotpassword" type="text" value="" id="forgotpassword" /></td> </tr> <tr> <td colspan="2" class="footer"><input type="submit" name="submit" value="Submit" class="mainoption" /></td> </tr> </table> </form> <? } ?> And now for the registration and password creation script Code: [Select] <?php $host = " "; $database = " "; $username = " "; $password = " "; mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); mysql_select_db($database); if ($_POST['form_submitted'] == '1') { ##User is registering, insert data until we can activate it $activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand(); $username = mysql_real_escape_string($_POST[username]); $email = mysql_real_escape_string($_POST[email]); ////////////////////////////////////////////////////////////////////////// $username= $_POST['username']; $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ echo "I'm sorry but the username you specified has already been taken. Please pick another one."; unset($username); $sendemail='0'; } /////////////////////////////////////////////////////////////////////////////////// $email= $_POST['email']; $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); $useremail_exist = mysql_num_rows($checkemail); if($useremail_exist > 0){ echo "I'm sorry but the email address you specified has already been taken. Please pick another one."; unset($email); $sendemail='0'; } ////////////////////////////////////////////////////////////////////////////// if ( $_POST['password'] == $_POST['password2'] && $username_exists <=0 && $useremail_exist <= 0) { $password = sha1($_POST['password']); $sql="INSERT INTO users (username, password, email, activationkey, status) VALUES ('$username', '$password', '$email', '$activationKey', 'verify')"; $sendemail = '1'; } else { echo "*Passwords do not match!"; $sendemail='0'; } if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } $_POST['form_submitted'] = '0'; //make form disappear. if ($sendemail =='1') { echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration."; } ##Send activation Email $to = $_POST[email]; $subject = " Registration"; $message = "Welcome to our website! verify_user.php?$activationKey\r\rIf this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ Team"; $headers = 'From: noreply@r.com' . "\r\n" . 'Reply-To: noreply@r.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } else { ##User isn't registering, check verify code and change activation code to null, status to activated on success $queryString = $_SERVER['QUERY_STRING']; $query = "SELECT * FROM users"; $result = mysql_query($query) or die(mysql_error()); /*if*/ while($row = mysql_fetch_array($result)){ if ($queryString == $row["activationkey"]){ $_POST['form_submitted'] = '2'; //make form disappear. echo "Congratulations!" . $row["username"] . " is now the proud new owner of an e.com account. Please sign in to the site at <a href='sign_in.php'>THIS LINK</a>. "; $sql=" UPDATE users SET status='activated' WHERE (id = $row[id])"; //UPDATE users SET activationkey = '', //$sql="UPDATE users SET activationkey = 'Done-$row[id]', status='activated' WHERE (id = $row[id])"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 { font-size: large; font-weight: bold; } .style3 {font-size: large} --> </style> </head> <body> <?php if (!isset ($_POST['form_submitted'])){ echo (' <div align="center"><span class="style3"> Please register. </span> <table border="0"> <form action="verify_user.php" method="post" name="register"> <tr><td>Username: <input type="text" name="username" maxlength="20"></td></tr> <tr><td>Password:<input type="password" name="password" /></td><td> <tr><td>Confirm password: <input type="password" name="password2" maxlength="20"></td><td> <tr><td> Email: <input type="text" name="email" /></td></tr> <input type="hidden" name="form_submitted" value="1"/> <tr><td><input type="submit" value="Submit" /></td></tr> </form> </table> </div>'); } if ( $_POST['form_submitted'] =='2'){ echo (" You may now enter the site!");//echo nothing no form. } ?> </body> </html> Im trying to access a page that uses a session hash in the url. How do I accomplish this. The url looks like: http://www.somesite.com/findagent/MapController.aspx?action=getAgentsByRadius&distance=5&filter=PL&sessionhash=%3F%01j%23%3Eo%0AH%05h%0B%3FU%0B%3F%3F%3F%7B%3F%3C&zip=91111 I guess getting the session id and urlencoding on my end wouldnt work? I would have to grab their session id and encode somehow? What is the difference between the hash algo "tiger192,3" and "tiger192,4"? I ran fsum/HashCalc to get a TIGER hash from a string and it is different with either "tiger192,3" or "tiger192,4". I also tried using the hash as hex string input to rehash 3 or 4 times, but still cannot get an equivalent to that of "tiger192,3" or "tiger192,4"... Im using SMF forum im trying to connect (my software C#) and grand access from forum DB this is a hash from SMF sha1(strtolower($membername) . $password); Code: [Select] <?php include("config.php"); $user = "-1"; if (isset($_GET['user'])) { $user = $_GET['user']; } $pass = "-1"; if (isset($_GET['pass'])) { $pass = $_GET['pass']; } $ip = $_SERVER['REMOTE_ADDR']; $sql = "select id_member,count from smf_members where real_name='$user' and passwd=MD5('$pass')"; $results = mysql_query($sql, $con); $values = mysql_fetch_assoc($results); $user_id = $values['id_member']; $login=$values['count']; ?> MD5 working fine but how to use SMF hash to login? |