467,888 Members | 1,620 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,888 developers. It's quick & easy.

Custom Authentication without Server

Hi,

I want to implement my own "primitive" Authentication.
I use following code in web.config:

<authentication mode="Forms">
<forms name="FwLoginCookie"
loginUrl="Login.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false">
<credentials passwordFormat="Clear">
<user name="private" password="private" />
<user name="test" password="test" />
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>

I created a Login.aspx page. When I try to login with test (test) I get
an sql server error:

An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: SQL Network Interfaces, error: 26 - Error
Locating Server/Instance Specified)

How do I create a page so I can log in with the credentials provided
within web.config?

Can I use the Login control and provide my own login (e.g. implemented
in my own library)?

Regards,

Rudi
Apr 4 '07 #1
  • viewed: 1323
Share:
7 Replies
On Apr 4, 10:15 am, Rudi Hausmann <rudi...@nospam.comwrote:
I created a Login.aspx page. When I try to login with test (test) I get
an sql server error:

An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: SQL Network Interfaces, error: 26 - Error
Locating Server/Instance Specified)
Are you sure that this error occured on the login.aspx?
login.aspx redirects back to the original page

Apr 4 '07 #2
Alexey Smirnov wrote:
On Apr 4, 10:15 am, Rudi Hausmann <rudi...@nospam.comwrote:
>I created a Login.aspx page. When I try to login with test (test) I get
an sql server error:

An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: SQL Network Interfaces, error: 26 - Error
Locating Server/Instance Specified)

Are you sure that this error occured on the login.aspx?
login.aspx redirects back to the original page
Yes, I am. When I press the Log In button I get the error above. I just
want the credentials to be read from web.config and not from a database
which I didn't set up and which I also don't want to set up.
Apr 4 '07 #3
On Apr 4, 11:36 am, Rudi Hausmann <rudi...@nospam.comwrote:
Yes, I am. When I press the Log In button I get the error above. I just
want the credentials to be read from web.config and not from a database
which I didn't set up and which I also don't want to set up.
Okay. Let's test it. Take my login.aspx and try to login with any of
your name

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Security " %>
<HTML>
<HEAD>
<title>Test</title>
</HEAD>
<body>
<form id="Form1" runat="server">

Name:<br />
<input id="UserName" type="text" runat="server"><br />

Password:<br />
<input id="Password1" type="password" runat="server"><br />

<input type="submit" OnServerClick="SubmitBtn_Click" runat="server"
ID="Submit1" NAME="Submit1" value="Try login!">

<asp:Label id="lblMsg" runat="server" />
</form>
<script language="vb" runat="server">

Sub SubmitBtn_Click(ByVal Source as Object, ByVal E as EventArgs)
If FormsAuthentication.Authenticate(Username.Value, UserPass.Value)
Then
FormsAuthentication.RedirectFromLoginPage (UserName.Value, false)
else
lblMsg.text="Credentials not valid!"
End If
End Sub

</script>
</body>
</HTML>

Apr 4 '07 #4
On Apr 4, 11:50 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Apr 4, 11:36 am, Rudi Hausmann <rudi...@nospam.comwrote:
Yes, I am. When I press the Log In button I get the error above. I just
want the credentials to be read from web.config and not from a database
which I didn't set up and which I also don't want to set up.

Okay. Let's test it. Take my login.aspx and try to login with any of
your name

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Security " %>
<HTML>
<HEAD>
<title>Test</title>
</HEAD>
<body>
<form id="Form1" runat="server">

Name:<br />
<input id="UserName" type="text" runat="server"><br />

Password:<br />
<input id="Password1" type="password" runat="server"><br />

<input type="submit" OnServerClick="SubmitBtn_Click" runat="server"
ID="Submit1" NAME="Submit1" value="Try login!">

<asp:Label id="lblMsg" runat="server" />
</form>
<script language="vb" runat="server">

Sub SubmitBtn_Click(ByVal Source as Object, ByVal E as EventArgs)
If FormsAuthentication.Authenticate(Username.Value, UserPass.Value)
Then
FormsAuthentication.RedirectFromLoginPage (UserName.Value, false)
else
lblMsg.text="Credentials not valid!"
End If
End Sub

</script>
</body>
</HTML>
Wait, add another Test.aspx form with the following code (just one
line of code):

----------
My User Name is: <%=User.Identity.Name%>
----------

Then

1) call this page http://localhost/Test.aspx
2) it will forward you http://localhost/Login.aspx
3) type username / password
4) if username / password were correct you will be redirected back to
http://localhost/Test.aspx
5) you should see your username

Apr 4 '07 #5
Hi Alexey,

Thanks a lot for answer and your effort!
I adapted the code until it run fine on my machine. (The code is below.)
Having your keywords in your code it`s much easier to come further.

I guess when exchange "FormsAuthentication.Authenticate" with
"MyOwnLogInTest(user,pass)" I can have my own authentication.

Moreover I assume that I can't use the asp.net login controls.

Regards,

Rudi

-------------------------------------
<%@ Page Language="VB" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Security " %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test</title>
</head>
<body>
<form id="Form1" runat="server">
Name:<br />
<input id="UserName" type="text" runat="server" /><br />
Password:<br />
<input id="UserPass" type="password" runat="server" /><br />
<input type="submit" onserverclick="SubmitBtn_Click"
runat="server" id="Submit1"
name="Submit1" value="Try login!" />
<asp:Label ID="lblMsg" runat="server" />
</form>

<script language="vb" runat="server">

Sub SubmitBtn_Click(ByVal Source As Object, ByVal E As EventArgs)
If FormsAuthentication.Authenticate(UserName.Value,
UserPass.Value) Then

FormsAuthentication.RedirectFromLoginPage(UserName .Value, False)
Else
lblMsg.Text = "Credentials not valid!"
End If
End Sub

</script>

</body>
</html>
Alexey Smirnov wrote:
On Apr 4, 11:36 am, Rudi Hausmann <rudi...@nospam.comwrote:
>Yes, I am. When I press the Log In button I get the error above. I just
want the credentials to be read from web.config and not from a database
which I didn't set up and which I also don't want to set up.

Okay. Let's test it. Take my login.aspx and try to login with any of
your name

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Security " %>
<HTML>
<HEAD>
<title>Test</title>
</HEAD>
<body>
<form id="Form1" runat="server">

Name:<br />
<input id="UserName" type="text" runat="server"><br />

Password:<br />
<input id="Password1" type="password" runat="server"><br />

<input type="submit" OnServerClick="SubmitBtn_Click" runat="server"
ID="Submit1" NAME="Submit1" value="Try login!">

<asp:Label id="lblMsg" runat="server" />
</form>
<script language="vb" runat="server">

Sub SubmitBtn_Click(ByVal Source as Object, ByVal E as EventArgs)
If FormsAuthentication.Authenticate(Username.Value, UserPass.Value)
Then
FormsAuthentication.RedirectFromLoginPage (UserName.Value, false)
else
lblMsg.text="Credentials not valid!"
End If
End Sub

</script>
</body>
</HTML>
Apr 4 '07 #6
Alexey Smirnov wrote:
On Apr 4, 11:50 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
>On Apr 4, 11:36 am, Rudi Hausmann <rudi...@nospam.comwrote:
>>Yes, I am. When I press the Log In button I get the error above. I just
want the credentials to be read from web.config and not from a database
which I didn't set up and which I also don't want to set up.
Okay. Let's test it. Take my login.aspx and try to login with any of
your name

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Security " %>
<HTML>
<HEAD>
<title>Test</title>
</HEAD>
<body>
<form id="Form1" runat="server">

Name:<br />
<input id="UserName" type="text" runat="server"><br />

Password:<br />
<input id="Password1" type="password" runat="server"><br />

<input type="submit" OnServerClick="SubmitBtn_Click" runat="server"
ID="Submit1" NAME="Submit1" value="Try login!">

<asp:Label id="lblMsg" runat="server" />
</form>
<script language="vb" runat="server">

Sub SubmitBtn_Click(ByVal Source as Object, ByVal E as EventArgs)
If FormsAuthentication.Authenticate(Username.Value, UserPass.Value)
Then
FormsAuthentication.RedirectFromLoginPage (UserName.Value, false)
else
lblMsg.text="Credentials not valid!"
End If
End Sub

</script>
</body>
</HTML>

Wait, add another Test.aspx form with the following code (just one
line of code):

----------
My User Name is: <%=User.Identity.Name%>
----------

Then

1) call this page http://localhost/Test.aspx
2) it will forward you http://localhost/Login.aspx
3) type username / password
4) if username / password were correct you will be redirected back to
http://localhost/Test.aspx
5) you should see your username
Works fine. I see what should see :-)
Thank you!
Apr 4 '07 #7
On Apr 4, 12:19 pm, Rudi Hausmann <rudi...@nospam.comwrote:
Alexey Smirnov wrote:
On Apr 4, 11:50 am, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Apr 4, 11:36 am, Rudi Hausmann <rudi...@nospam.comwrote:
>Yes, I am. When I press the Log In button I get the error above. I just
want the credentials to be read from web.config and not from a database
which I didn't set up and which I also don't want to set up.
Okay. Let's test it. Take my login.aspx and try to login with any of
your name
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Security " %>
<HTML>
<HEAD>
<title>Test</title>
</HEAD>
<body>
<form id="Form1" runat="server">
Name:<br />
<input id="UserName" type="text" runat="server"><br />
Password:<br />
<input id="Password1" type="password" runat="server"><br />
<input type="submit" OnServerClick="SubmitBtn_Click" runat="server"
ID="Submit1" NAME="Submit1" value="Try login!">
<asp:Label id="lblMsg" runat="server" />
</form>
<script language="vb" runat="server">
Sub SubmitBtn_Click(ByVal Source as Object, ByVal E as EventArgs)
If FormsAuthentication.Authenticate(Username.Value, UserPass.Value)
Then
FormsAuthentication.RedirectFromLoginPage (UserName.Value, false)
else
lblMsg.text="Credentials not valid!"
End If
End Sub
</script>
</body>
</HTML>
Wait, add another Test.aspx form with the following code (just one
line of code):
----------
My User Name is: <%=User.Identity.Name%>
----------
Then
1) call this pagehttp://localhost/Test.aspx
2) it will forward youhttp://localhost/Login.aspx
3) type username / password
4) if username / password were correct you will be redirected back to
http://localhost/Test.aspx
5) you should see your username

Works fine. I see what should see :-)
Thank you!- Hide quoted text -

- Show quoted text -
Kein Problem :-)

Apr 4 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Nick | last post: by
6 posts views Thread by Jéjé | last post: by
5 posts views Thread by Jon Skeet [C# MVP] | last post: by
1 post views Thread by Jakob Lithner | last post: by
6 posts views Thread by =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.