ASP.Net MVC application does not connect to the bank

Asked

Viewed 141 times

3

I’m developing a Solution in the object-oriented programming class for the web. Let’s create a stock control system. One of the first "screens" of access, is the login, only at this moment, my entire 'application' already goes downhill.

In the first screen, we have the login and password field, when we click on the 'login' button is called a method, which queries the login in the bank, but the return is always 'Invalid login'

Method FazLogin

        return Contexto.tblUsuario
        .Where(u => u.LOGIN == usuario && u.SENHA == senha).FirstOrDefault() != null; 

Through Visual Studio itself, if we make a query in the database, I can see the table tblUsuario and I can also see my users for testing. In the Connection string, it’s like this:

<connectionStrings>
<add name="ModeloEstoqueContextoContainer" connectionString="metadata=res://*/ModeloEstoqueContexto.csdl|res://*/ModeloEstoqueContexto.ssdl|res://*/ModeloEstoqueContexto.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LENOVO-PC\SQLEXPRESS;initial catalog=ESTOQUE_DATABASE;user id=sa;password=SENHAXXXXX;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

We are working on the MVC model, and yes, the references have been checked several times, both by me and the teacher.


@Gypsy, Metadata (Connection String) is automatically generated by Entity Framework

@pnet, The password is not encrypted, it is a very simple thing that we are doing in college, when typing the password, we have a answer. Redirect that directs to the other page. By debugging always Count = 0 and values are null.

I’m not getting the controller here.

  • This connetion string is very suspicious. What is the need to pass the Metadata on it?

  • Dude, a question. At your bank is the password encrypted? If you are, you would need to decrypt to make the comparison. Something else, debugging your Return, is something coming? Can you post your controller so we can understand better? This is easier. As for Morrison’s comment, this is normal, because Entity already mounts it like this, with Metadata. It’s the same with me and it works properly.

1 answer

2

Dude, I made a simple login screen with MVC and worked like this. Build in the controller a method that would take the bank logged in guy, like you do. Then he would serialize the information through a Jsonresult and send it to a jquery function that would deselect the result of the Scan, validate it and then call the corresponding screen. That’s how I did it and it never gave me a headache. See below the codes.

Controller:

[HttpPost]
        public JsonResult ValidaLogin(string _email, string _senha)
        {
            INETGLOBALEntities db = new INETGLOBALEntities();

            EncriptyDecripty cripto = new EncriptyDecripty();

            string s = cripto.Encrypt(_senha);

              var  result_login = (from login in db.tbl_usuario
                                    where login.email == _email && login.senha_usuario == _senha
                                    select new { login.email, login.nm_usuario }).ToList();

             if(result_login.Count > 0)
             {
                return Json(new { result_login }, JsonRequestBehavior.AllowGet);

             }
             else
             {
                return Json(JsonRequestBehavior.AllowGet);
             }
        }

Jquery:

function ValidaLogin() {

    $.ajax({
        url: '/Login/ValidaLogin',
        datatype: 'json',
        contentType: "application/json; charset=utf-8",
        type: "POST",
        data: JSON.stringify({ _email: $('#inputEmail').val(), _senha: $('#inputPassword').val() }),
        success: function (data) {

            $(data.result_login).each(function () {
                if (this.email != '' || this.email != null)
                    $(window.document.location).attr('href', '/Pesquisa/Pesquisa');
            });
        },
        error: function (error) {

            alert('Usuário ou senha digitados de forma incorreta.');
        }
    });
}

That’s it, and you never stuck with me working like that.

Browser other questions tagged

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