Posted By

ofadlaoui on 08/05/10


Tagged

password to stars


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ofadlaoui


From password string to stars (*)


 / Published in: PHP
 

This simple snipplr will convert an password string to an censored string by stars (*). Usage:\r\n$myPwdCensored=passToStars(\\"password\\");\r\necho $myPwdCensored;\r\nI made this in 5min Comment and FAV ! :-)\r\nMore PHP \"Snipplr\"s coming soon !

  1. <?php
  2. function passToStars($password) {
  3. //Convert an password into stars (*) with PHP
  4. //© ofadlaoui @ Snipplr.com
  5. $password = strlen($password); //lenght of password
  6. $number = 0;
  7. $stars = ""; //empty string
  8. while ($number != $password) //While an number isn't the lenght of the password..
  9. {
  10. $stars += "*"; //.. PHP will add an star to the empty string.
  11. $number++; //If we don't excecute this, the page $stars will be unlimited.
  12. }
  13. return $stars;
  14. }
  15. // Usage:
  16. $myPwdCensored=passToStars("password");
  17. echo $myPwdCensored;
  18. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Sverri on August 7, 2010

function passToStars($password) { return str_repeat('*', strlen($password)); }

Posted By: ofadlaoui on August 8, 2010

@Sverri Lol thanks, but you can submit an new snipplr, because now you're ruin my snippet..

Posted By: cigraphics on August 11, 2010

sorry for saying this but this is kinda stupid because you are turning on the guesses never ever do that on a production website.

if you want to censor pass just put **** stars not the lenght of the pass

Posted By: tekagami on October 16, 2012

needs to have line 10 changed to:

$stars .= "*"; //.. PHP will add an star to the empty string.

You need to login to post a comment.