Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I need to create a Secure login form in Web API and I do NOT want to pass the Login values via URL to redirect page.My problem is :
I can check weather the Username and Password is correct (exist in SQL DB), but I don't know how to pass values to redirected page (Home.html) so User can redirect to him/her own Home page with his personal info.

What I have tried:

Controller:
C#
public class LoginAuthenticateArgs
{
  public string Username {get; set;}
  public string Password {get; set;}
}


[HttpPost]
public int LoginAuthenticate(LoginAuthenticateArgs _Login)
{
  using(Product _Product = new Product())
  {
    var _UserLogin = _Product.Login
                              .where(c=>c.Username == _Login.Username &&
                                        c.Password == _Login.Password)
                               .singleordefault();
    if(_UserLogin != null)
    {
       return _UserLogin .ID;
    }
  }
}


JavaScript:
JavaScript
function LoginClick(){
 var data = {
   Username: $("#UsernameTextbox").val(),
   Password: $("#PasswordTextbox").val()
 };
 Ajax("Controller/function", data, Success, Fail, "post"};
};

function Success(response){
  // I don't know what to do now and how to pass the response
  // to redirect page
};
Posted
Updated 13-Nov-16 23:33pm
Comments
F-ES Sitecore 14-Nov-16 5:19am    
It is pointless to use AJAX when redirecting someone to a new page, just use a normal form and you get the benefit if your site still working without js.
Ali Majed HA 14-Nov-16 13:12pm    
Thanks for your comment,I will keep it in mind.
Richard Deeming 14-Nov-16 12:08pm    
You are storing passwords in plain text. That is an extremely bad idea.

You should only ever store a salted hash of the password, using multiple iterations of a secure hashing algorithm, and a unique salt for each record.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Ali Majed HA 14-Nov-16 13:13pm    
Hey Richard, Your comment has opened new window for me, thanks a lot.

Try this:
if (response.Id != undefined && response.Id != null) {
window.location = '/home?Id=' + response.Id;
 
Share this answer
 
Comments
Ali Majed HA 15-Nov-16 0:10am    
Hello
Thanks for your Answer but is passing the username via URL Safe ?
How can I retrieve it?
HI,

You can use window.sessionStorage in jquery.
 
Share this answer
 
Comments
Ali Majed HA 15-Nov-16 0:14am    
Hello
Thanks a lot, You have solved my problem, Thanks again

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900