Jump to content


Mr-Chidi

Member Since 20 May 2008
Offline Last Active Nov 17 2014 03:48 AM

Topics I've Started

Make Selected Values Appear as List

13 November 2014 - 01:23 AM

Hi all.

 

how can i make the values show like a list. I tried html line break "<br>" and php \n but all to no avail. It just show all the values in one straigth line.

 

example of what i want is for the values to appear like this:

 

1234567890

0987654345

4567890675

 

instead of :

 

1234567890 0987654345 4567890675

 

Thanks

 
<form data-abide method="post" action="">
<div>
<select name="">
  <option value="name">
  <?php
$stmt = $pdo->query("SELECT acct_num FROM table order by id desc");
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
echo $row['acct_num'];
}
 
  ?>
</option>
</select>
</div>
<div>
    <label>New Password <small>required</small></label>
    <input type="password" name="password" id="password" required>
    <small class="error">New password is required and must be a string.</small>
</div>
<div>
    <label>Confirm New Password <small>required</small></label>
    <input type="password" name="password2" id="password2" required>
    <small class="error">Password must match.</small>
</div>
 

<input name="submit" type="submit" class="button small" value="Change Password">
</form>

Help with understanding password_hash

08 November 2014 - 08:39 AM

Hi.

 

I've been trying to understand the concept of password_hash but so far it has eluded me!

 

registration

<?php

if(isset($_POST['submit'])){

    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    //$pass_hash = PassHash::hash($_POST['password']);
    $hash = password_hash($password, PASSWORD_BCRYPT);
    
    $stmt = $pdo->prepare("INSERT INTO hash_test(name, email, password) VALUES(:name, :email, :password)");
    $stmt->execute(array(
    ':name' => $name,
    ':email' => $email,
    ':password' => $hash
    ));
    
    if ($stmt->rowCount() ==1){
        echo "Registration Successful";
    }else{
        echo "There was a problem taking your request";
    }
}
?>

 

The registration is working fine and all fields are inserted. The problem is when loggin in, its giving me an error : unknown variable which is the $hash. The verify parameter is thus:

 

password_verify($password, $hash)

 

I believe the $password is the users password for login, now how/when/where do assign a value to $hash?  since in my db i have email(username) password. Do i need to store the hash separately on the db? Can someone please enlighten me more

 

my login code

 
<?php

if(isset($_POST['login'])){
    
$password = $_POST['password'];

$stmt = $pdo->prepare("SELECT email, password FROM hash_test WHERE email=:email AND password=:password");
$stmt->execute(array(
':email' => $_POST['email'],
':password' =>$password
));

//if ($stmt->rowCount() ==1){
if (password_verify($password, $hash)) {
        /* Valid */
        echo "Right";
    } else {
        /* Invalid */
        echo "wrong";
    }
//}
}

?>
 

 

THANKS

 


View All Date Diffrence

07 November 2014 - 04:57 PM

Hi all.
How can i see all the difference between two dates in a column. I know to see a single date difference we can do:

$stmt = $pdo->query("SELECT DATEDIFF(date_paid, next_due) AS diffdate FROM table_name");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo $row['diffdate'];
}

but i want all the difference to show in a table along with other details.

thanks


Why is this not loggin me in

25 October 2014 - 12:16 AM

Hi all. I'm really having an awful time. Pls what could be the problem with this cos i can login into my local server but cant login when i go live.

 

thanks

<?php    
if(isset($_POST['login'])){

$username=$_POST['username'];
$password=$_POST['password'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$pass = md5($password);


$stmt = $pdo->prepare("SELECT * FROM confirm WHERE username=:username AND password=:password");
$stmt->execute(array(
':username' =>$username,
':password' => $pass
));

if ($stmt->rowCount() ==1){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("location: ./account/");
exit();
}
else {
echo 'Invalid Username or Password';
}
    }
?> 

Locking user based on ip

20 October 2014 - 07:01 AM

I know something is wrong but dunno how to fix it. My intention is to lock user based on ip after 3 unsuccessful attempts. Its incrementing the login count but after 3 attempts, I just can't figure out how to lock the user and reset the value after some time.

I'd like a pointer towards the right/best thing to do should my code not be worthy.

Thanks and heres my code:

 <?php

$user_ip = $_SERVER['REMOTE_ADDR'];
$table_name = "loginattempts";

$query = "SELECT attempts FROM $table_name WHERE user_ip = '$user_ip'";
$result = mysql_query($query) or die("Invalid Login");

while($row = mysql_fetch_array($result)){
	$count = $row['attempts'];
}
if($count == 3){
	echo("Your login attempt is completed");
	
}else{
	$insert = "INSERT INTO $table_name WHERE user_ip = '$user_ip'";
	$result = mysql_query($insert);

	$update = "UPDATE $table_name SET attempts = attempts + 1 WHERE user_ip = '$user_ip'";
	$result = mysql_query($update);
}
$update = "UPDATE $table_name SET attempts = 0 WHERE lastlogin - NOW() = '60000'";
$result =  mysql_query($update);

?>

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com