Cacher le texte saisi dans un prompt

Fermé
abirgl Messages postés 127 Date d'inscription lundi 31 octobre 2016 Statut Membre Dernière intervention 20 juin 2017 - 6 févr. 2017 à 14:35
nagaD.scar Messages postés 4272 Date d'inscription samedi 8 septembre 2007 Statut Membre Dernière intervention 4 janvier 2023 - 6 févr. 2017 à 16:11
Bonjour,
Pour valider l'accès d'un client à son espace , je lui affiche un prompt pour qu'il saisisse son mot de passe, mais le texte qu'il saisit est affiché, je veux cacher ce texte en des étoiles, comme si il saisit son texte dans un password field,
Pouvez vous m'aider SVP ??

1 réponse

nagaD.scar Messages postés 4272 Date d'inscription samedi 8 septembre 2007 Statut Membre Dernière intervention 4 janvier 2023 251
6 févr. 2017 à 15:27
J avais mal lu (j avais vu le prompt).

Bref, en clair non tu ne peux pas masque le prompt, par contre tu peux faire quelque chose comme :

<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}
?>


naga
0
abirgl Messages postés 127 Date d'inscription lundi 31 octobre 2016 Statut Membre Dernière intervention 20 juin 2017
6 févr. 2017 à 15:37
Merci Naga mais ça ne convient pas à mon besoin :( je voulais bien quelque chose comme ça mais en javascript , avez vous une autre idée ?
0
nagaD.scar Messages postés 4272 Date d'inscription samedi 8 septembre 2007 Statut Membre Dernière intervention 4 janvier 2023 251
6 févr. 2017 à 16:03
Le soucis étant que le prompt est géré par le navigateur et donc non mangeable via le code (j avais eu aussi ce besoin).

J'avais bien trouvé une solution mais extrêmement lourde : créer une div "par dessus" ton corp avec une zone input type password.


Je n arrive pas à retrouver le code (je suis justement sur un projet ou j en aurai besoin) mais si je mets la main dessus je redis.

naga
0
nagaD.scar Messages postés 4272 Date d'inscription samedi 8 septembre 2007 Statut Membre Dernière intervention 4 janvier 2023 251
6 févr. 2017 à 16:06
en fait j avais posté la source x)
Mais attention, ce n'est que le code du prompt, mais concernant la mise en page c'est très très moche, bref à adapter a ton besoin quoi:

https://codes-sources.commentcamarche.net/source/101575-js-popup-de-saisie


naga
0
nagaD.scar Messages postés 4272 Date d'inscription samedi 8 septembre 2007 Statut Membre Dernière intervention 4 janvier 2023 251 > nagaD.scar Messages postés 4272 Date d'inscription samedi 8 septembre 2007 Statut Membre Dernière intervention 4 janvier 2023
6 févr. 2017 à 16:11
je te l ai adapté pour le pass:

<html>
<head>
<script>

function JSform (ObjectName , divTitle , mainDiv ){

this.targetValidation = "";

this.myID = "JSfrom";
this.myName = ObjectName;
this.cursorElem=0;
this.elemTitle = divTitle;
this.elements= new Array();
this.motherDIVid = mainDiv;
this.results = null;
/**********************************************************/
this.addInput = function (sLib , sID){
this.elements[this.cursorElem]=new Array();
this.elements[this.cursorElem][0]=sID;
this.elements[this.cursorElem][1] = (sLib == "" ? "" : sLib)+"<input type='text' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"' id='"+sID+"' />";
this.cursorElem++;
}
/**********************************************************/
this.addInputPass = function (sLib , sID){
this.elements[this.cursorElem]=new Array();
this.elements[this.cursorElem][0]=sID;
this.elements[this.cursorElem][1] = (sLib == "" ? "" : sLib)+"<input type='password' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"' id='"+sID+"' />";
this.cursorElem++;
}
/**********************************************************/
this.addOpt = function (tOpt,sID){
for(i = 0 ; i < tOpt.length ; i++ ){
this.elements[this.cursorElem]=new Array();
this.elements[this.cursorElem][0]=sID + "_" + i;
if(tOpt[i].length > 1 ){
this.elements[this.cursorElem][1] = "<label><input type='checkbox' id='"+sID+ "_" + i+"' value='"+tOpt[i][0]+"' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"'>"+tOpt[i][1]+"</label>";
} else {
this.elements[this.cursorElem][1] = "<label><input type='checkbox' id='"+sID+ "_" + i+"' value='"+tOpt[i]+"' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"'>"+tOpt[i]+"</label>";
}
this.cursorElem++;
}
}
/**********************************************************/
this.start = function () {
var elCont = document.getElementById(this.myID);
if( elCont != null){
elCont.parentNode.removeChild(elCont);
}
elCont = document.createElement("div");
elCont.id = this.myID;

document.getElementById(this.motherDIVid).style.opacity=0.4;
elCont.style.display = "block"; // ... on l'affiche...
elCont.style.position="absolute";
elCont.style.top="40%";
elCont.style.right="40%";
elCont.style.border="solid";
elCont.style.zIndex ="99";

var HTMLvalue = "";
if(this.elemTitle != ""){
HTMLvalue = "<h1>" + this.elemTitle + "</h1>";
}
for(i = 0 ; i < this.cursorElem ; i ++){
HTMLvalue += this.elements[i][1];
}
elCont.innerHTML =HTMLvalue;
document.body.insertBefore(elCont, document.body.childNodes[0]);
document.getElementById(this.elements[0][0]).focus();
}
/**********************************************************/
this.doValidation = function() {
this.results = new Array();
for(i = 0 ; i < this.cursorElem ; i ++){
this.results[this.elements[i][0]] = document.getElementById(this.elements[i][0]).value;
}
document.getElementById(this.motherDIVid).style.opacity=1;

var elCont = document.getElementById(this.myID);
elCont.parentNode.removeChild(elCont);
if(this.targetValidation != ""){
this.targetValidation(this.results);
}
}
/**********************************************************/
this.keyPressedHere = function (e) {
if(window.event.keyCode == 13) {
for(i = 0 ; i < this.cursorElem ; i ++){
if( document.activeElement.id == this.elements[i][0]){
if( i == (this.cursorElem-1)){
this.doValidation( );
}
else {
document.getElementById(this.elements[i+1][0]).focus();
break;
}
}
}
}
}

}
</script>

</head>

<body>



<DIV ID="MAIN" style="position:relative;z-index:5;Width:80%;height:80%;background: none repeat scroll 0% 0% #000;">
</DIV>


<script>
var ot = new JSform("ot","titre","MAIN");
ot.addInputPass("Password:","myPass");
ot.start();
ot.targetValidation = function (ar) {
alert(ar['myPass']);
}
</script>


</body>

</html>


0