Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP replace all characters with asterisk

Tags:

php

So lets say I have a password in the form of a string:

$password = "thisisaplaintextpassword"

How can I turn it into the following?

$password = "************************"

I would like to send users their account details via email, and don't want to send the entire thing.

like image 754
ThatGuy343 Avatar asked Sep 22 '14 07:09

ThatGuy343


2 Answers

Use str_repeat

$password = str_repeat("*", strlen($password)); 
like image 127
cornelb Avatar answered Sep 26 '22 04:09

cornelb


function hidePassword($p) {
    $fit = strlen($p);
    return sprintf("%'*-${fit}s",false);
}

echo hidePassword($p);
like image 20
John V Avatar answered Sep 25 '22 04:09

John V