如何將密碼字符串轉換爲指定的符號,如*
或其他。如何將字符串轉換爲PHP中的符號
我目前正在修改密碼頁面。 我想顯示密碼到頁面,我想避免密碼忽視某人,所以我想隱藏密碼的字符串像*
相同長度的符號。 例如<input type="password" />
。
對不起我的英文不好...
如何將密碼字符串轉換爲指定的符號,如*
或其他。如何將字符串轉換爲PHP中的符號
我目前正在修改密碼頁面。 我想顯示密碼到頁面,我想避免密碼忽視某人,所以我想隱藏密碼的字符串像*
相同長度的符號。 例如<input type="password" />
。
對不起我的英文不好...
$output_password = str_repeat ('*', strlen ($input_password));
做這樣的:
$passwordstring = "password";
$outputpassword = "";
while(strlen($outputpassword)<strlen($passwordstring))
{
$outputpassword .= "*";
}
echo $outputpassword
嘗試使用建立像str_repeat這樣的函數;)。 – Styxxy
一種方法是使用類型密碼的輸入,但其設置爲禁用。
<input type='password' disabled='disabled' value='somepassword' />
如果你正在尋找一種簡單的方法來只創建星號等於密碼的長度的字符串:
$modified = str_repeat("*", strlen("secretpass"));
echo $modified; // **********
你不輸出密碼在你的HTML中,你創建了一個asterix(*
)你的密碼錶示。這很容易被str_repeat函數來完成:
<?php
$password = "MyPasswordThatIWantToMask";
$maskedPassword = str_repeat("*", strlen($password));
?>
現在你只輸出$maskedPassword
作爲密碼字段的值。
但是,另一個很有意思的事情是:你怎麼知道用戶的密碼長度?我真誠地希望你哈希你的密碼,而不是讓他們圍繞純文本。
雖然有很多答案在這裏展示str_repeat()
的用戶,我有點懷疑這是你想要的。畢竟,任何白癡都可以用一個字符來填充一個字符串,如果你可以簡單地使用它,那麼就沒有什麼意義了,正如你正確地指出的那樣,<input type="password" />
(是的,你仍然可以從源代碼中獲取密碼,但爲什麼麻煩填充混淆字段?或者不是隻填充靜態固定數量的*字符?)。
我懷疑你正在尋找的東西更多的是這樣的:
<?php
$thePassword = "thisIsMyPassword";
?>
<input type="text" id="input_user_types_in" value="<?php echo str_repeat('*', strlen($thePassword)); ?>" />
<input type="hidden" id="value_to_post_back" name="value_to_post_back" value="<?php echo $thePassword; ?>" />
<script type="text/javascript">
var textInput = document.getElementById('input_user_types_in');
var hiddenInput = document.getElementById('value_to_post_back');
textInput.onfocus = function() {
this.value = hiddenInput.value;
};
textInput.onblur = function() {
var i;
hiddenInput.value = this.value;
this.value = '';
for (i = 0; i < hiddenInput.value.length; i++) {
this.value = this.value + '*';
}
};
</script>
有一個fiddle與它周圍;-)
你是如何存儲你是能夠再次找回密碼?你應該散列密碼,而不是在頁面上顯示它們。 –
@火箭真,雖然它取決於應用程序。我花了很多時間在無線路由器上進行編程/修復/呼叫,當我無法從路由器中檢索當前編程的WPA密鑰時,它真的讓我感到厭煩,所以我不得不重置它,因爲一些白癡最終用戶忘記了什麼他們將其設置爲,然後我必須在手機上花費3個小時向他們解釋如何讓Windows忘記無線網絡,以便您可以重新加入並重新設置密鑰並<重呼吸> grrrr ..... – DaveRandom