Javascript check if the Windows user is registered in MS Access Database

Asked

Viewed 493 times

0

The need is to check if the Windows user is registered in the Ms Access database (network database), but is not working as it should. I think the problem is in the strUserName variable inside select.

I’ve tried several ways but still haven’t found the solution!

Someone knows how I fix it?

< html > < body >


  <!-- PEGA USUARIO LOGADO NO WINDOWS -->

< script type = "text/javascript" >
var objNet = new ActiveXObject("WScript.NetWork");
var strUserName = objNet.UserName;
var strDomain = objNet.UserDomain;


document.write("Usuário: ", strUserName);



function abreRelJC() {

  var adoConn = new ActiveXObject("ADODB.Connection");
  var adoRS = new ActiveXObject("ADODB.Recordset");

  adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='P:\\PCP\\GERENCIAL\\System\\GERENCIAL_be.mdb'");
  adoRS.Open("Select * From CadastroUser WHERE UsuarioRelatorioGerencial = strUserName", adoConn, 1, 3);

  var Userbanco = adoRS.fields("UsuarioRelatorioGerencial").value;



  if (Userbanco == strUserName) {

    document.write("Ok! usuário cadastrado");

    adoRS.Close();
    adoConn.Close();
  } else {

    document.write("Usuário pendente de cadastro!");

    adoRS.Close();
    adoConn.Close();
  }

}


< /script>


<br / > < br / >


< input type = "button"
onclick = "abreRelJC()"
value = "Testa usuáro"
style = "font-size:20px; color:SlateGray" / >


  < /body>< /html>

1 answer

1

Have you tried:

adoRS.Open("Select * From CadastroUser WHERE UsuarioRelatorioGerencial = " + strUserName, adoConn, 1, 3, 1);

?

Similarly on Document.write:

document.write("Usuário: " +  strUserName);

If the network console or javascript returns an error, please post it

Correction: To try adoRS.Open("Select * From Cadastrouser WHERE Usuariorelatoriogerencial = " + strUserName, adoConn, 1, 3, 1);

  • That would probably work. I don’t know the purpose of this application but I would like to alert the security flaw, since the access to the database is in the Client making it possible to change the SQL script and perform an SQL inject.

  • So jefissu, I had been trying and is in it, the first Document.write ("User: ", strUserName); it even displays the Windows user, but the Document.write within If do not work. ERROR: Message: No value was provided for one or more required parameters. Line: 20 Character: 12 Code: 0 URI: file://C:/Documents%20and%20Settings/asimoes/Desktop/pergunta%20javascript.html

  • Luã, thanks for the tip! I will pay attention despite this script run only on the intranet, it will be just a menu that will open some documents . xlsx that are on the network, but can only access users who are registered in a Access database.

  • According to https://msdn.microsoft.com/en-us/library/windows/desktop/ms676573(v=vs.85). aspx It seems to me that this asks for 5 parameters instead of 4... Try to put one more parameter at the end of the open worth 1

  • @jefissu, it didn’t work either, but I noticed that if you replace the variable strUserName in Select with the windows user in my case "asimoes", it works correctly, then the problem must be in select not recognizing the variable strUserName that contains value taken by the method objNet.Username; that is the windows user! will need to convert strUserName to some other way before passing it in Select?

  • If you run in the javascript console or in the code: Alert(strUserName) or console.log(strUserName) what it returns?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.