Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to work login without the help of stored procedure?
Posted

There are several ways to do this

if you are having database then you can go for stored procedure or dynamic queries.

You can also use file to store user credentials and when user login to the system read data from file and authenticate user.
 
Share this answer
 
Are you looking for something like this: User Login With XML...[^]

Since above one is in Vb, converting important snippets in C# for you.
1. Place ASP.NET Login Control on a web page.

2. XML File:
XML
<?xml version="1.0" encoding="utf-8" ?>
<Staff>
  <User>
    <username>aspxcode</username>
    <password>2008</password>
  </User>
    <User>
    <username>windows</username>
    <password>vista</password>
  </User>
</Staff>

3. Code behind:
C#
protected void Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
{
	string username = null;
	string pwd = null;
	string CurrentUser = "";
	string CurrentPwd = "";
	bool LoginStatus = false;

	username = Login1.UserName;
	pwd = Login1.Password;

	XmlDocument xd = new XmlDocument();
	xd.Load(Server.MapPath("~/App_Data/AllUser.xml"));

	XmlNodeList xnl = xd.GetElementsByTagName("User");

	foreach (XmlNode xn in xnl) {
		XmlNodeList cxnl = xn.ChildNodes;
		foreach (XmlNode cxn in cxnl) {
			if (cxn.Name == "username") {
				if (cxn.InnerText == username) {
					CurrentUser = username;
				}
			}

			if (cxn.Name == "password") {
				if (cxn.InnerText == pwd) {
					CurrentPwd = pwd;
				}
			}
		}

		if ((!string.IsNullOrEmpty(CurrentUser)) & (!string.IsNullOrEmpty(CurrentPwd))) {
			LoginStatus = true;
		}
	}

	if (LoginStatus == true) {
		Session("UserAuthentication") = username;
		Session.Timeout = 1;

		Response.Redirect("how-to-StartPage.aspx");
	} else {
		Session("UserAuthentication") = "";
	}
}


Try!
 
Share this answer
 
I made a user token and saved it to a file, when login is successful.
if log-out, delete file.

eg

C#
public class UserToken
{
    private int UserID; //ContactID
    private string MagicString;
    private static Random Generator = new Random();
    private int MAX = (int) Math.Pow(2,16);

//if user returns or send request check if file still exists
//else show login screen...

private void GenerateMagicToken()
    {
        MagicString = string.Empty;
        int MagicInt = Generator.Next(MAX);
        MagicString = MagicInt.ToString();
        //write to file
        string path = Folder + UserID.ToString() +".token";
        if (File.Exists(path)) //prevent more than one token per user- ie Login only once!!!
        {
            throw new Exception("User is already Logged in!");
        }
        else
        {
            using (StreamWriter sw = File.CreateText(path))
            {
                sw.WriteLine(MagicString);
                
            }
        }
    }

}
 
Share this answer
 

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