From password string to stars (*)


/ Published in: PHP
Save to your folder(s)

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 !


Copy this code and paste it in your HTML
  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

You need to login to post a comment.