如何隐藏数据并显示为****

时间:2015-08-05 13:09:20

标签: javascript php html

这是我的问题这是表

enter image description here

以下是显示表格的代码

class RequestHandlerApi extends AsyncTask<String,String, String>{

    private Context contextMain;



   @Override
   protected String doInBackground(String... url) {

    try{
        URL urlHarassmentApi = new URL("http://10.0.2.2:5000/geo-api");
        HttpURLConnection connMain = (HttpURLConnection)urlHarassmentApi.openConnection();
        connMain.setRequestProperty("Accept", "application/json");
        connMain.setRequestMethod("GET");
        Log.d("Hello",""+connMain);

        /*
        if (connMain.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + connMain.getResponseCode());
        }*/

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(connMain.getInputStream()));


        StringBuilder response = new StringBuilder();
        String inputLine;

        while ((inputLine = reader.readLine()) != null) {
            response.append(inputLine);

        }


        reader.close();



            try {
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(contextMain.openFileOutput("config.json", Context.MODE_PRIVATE));
                outputStreamWriter.write(response.toString());
                outputStreamWriter.close();
            }
            catch (IOException e) {
                Log.e("Exception", "File write failed: " + e.toString());
            }


    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
}

官员的详细信息存储在官员中我希望通过*******隐藏密码字段,就像 <tbody> <?php for($i=0;$i<count($details);$i++):?> <tr> <td><?=$details[$i]['id'];?></td> <td><?=$details[$i]['officer_id'];?></td> <td type="password"><?=$details[$i]['password'];?> <a href="">show</a></td> <td><?=$details[$i]['set'];?></td> </tr> <?php endfor; ?> </tbody> 如何在该表中显示input type=password而不是实际密码一样应该有一个链接/点击显示哪个显示密码,另一个点击隐藏它密码可见性应切换点击如果我可以使用jquery并切换密码可见性

7 个答案:

答案 0 :(得分:1)

您应该只为所有条目显示***。密码的长度称为元数据,这可以帮助其他人破解密码(考虑一下这一事实,他们知道长度是蛮力攻击非常有用的信息)。

在代码中,更改:

<td type="password"><?=$details[$i]['password'];?></td>

为:

<td>***</td>

第二点是:为什么用纯文本保存密码?出于安全和隐私原因,您应该只保存密码的哈希值。用户密码只应由用户自己知道。您和您的应用程序不需要知道普通密码:)

答案 1 :(得分:1)

我不确定您为什么要显示密码列,但如果您需要用星号替换密码,这将有所帮助:

<td type="password"><?=str_repeat("*", strlen($details[$i]['password']));?></td>

答案 2 :(得分:1)

我有一个简单的解决方案。

您想要屏蔽密码的原因可能是因为用户没有看到它。如果是这种情况,请不要在表格中显示密码列。

如果他们确实想要查看密码或对其进行编辑,请在其他可以进行更改的地方提供一个链接,但不会看到现有密码。

答案 3 :(得分:1)

如果您想要与原始密码相同的长度:

$PWlength = strlen($details[$i]['password']);

$newPW = '';
for ($i=0; $i<$PWlength; $i++) {
$newPW = $newPW."*";
}

echo $newPW;

请参阅其他答案。 - &GT;安全

我能想到这样做的唯一原因是,如果你想在某个动作之后显示密码,比如将鼠标悬停在元素上。 这可以通过Javascript实现。

这里的人总是消极的。但他们经常也是对的。所以请检查安全设置/方法!

答案 4 :(得分:0)

您可以获取元素,然后将属性设置为不显示。

var element = document.getElementById("id");

if(condition){
       element.style.display = 'none';
    }
else{
       element.style.display = 'block';
    }

答案 5 :(得分:0)

更改。

<td type="password"><?=$details[$i]['password'];?></td>

<td><input type="password" value="<?=$details[$i]['password'];?>" readonly/></td>

答案 6 :(得分:-1)

    <tbody>
      <?php for($i=0;$i<count($details);$i++):?>
        <tr>
          <td><?=$details[$i]['id'];?></td>
          <td><?=$details[$i]['officer_id'];?></td>
          <td>******<button onclick=<?php echo "alert(\"$details[$i]['password']\")"?>>Show Password</button></td>
          <td><?=$details[$i]['set'];?></td>
        </tr>
      <?php endfor; ?>
    </tbody>