0

Hi Guys,

im confused here,

im writing a script to show password as *.

My code at this minute does the following.

Passwords retrieved from database,
Password gets counted,
Password then gets changed into *
Password then gets printed to screen,

The code i have just now.

<?php
		  	$user = $_SESSION['myusername'];
	$data = mysql_query("SELECT * FROM `members` WHERE username='$user'");
		   while($row = mysql_fetch_array($data, MYSQL_ASSOC))
	 		{
			$password = "{$row['password']}";
			$length = strlen($password);
			$start = "*";
			$new_pword = str_replace($password, $start, $password);
		   echo "$new_pword"; 
		   }
		   ?>

my problem is that it only shows 1 star when it should count the password and use that many stars

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by pritaeas
0

if you have a look in the manual (php.net/str_replace) you can see that you are instructing php to replace the whole word with a single star.

$password = preg_replace('.', '*', $password);
// or
$password = str_repeat('*', $length);

Edited by pritaeas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.