help in converting this custom login script

Last post 08-18-2003 10:46 AM by gregw. 3 replies.

Sort Posts:

  • help in converting this custom login script

    08-15-2003, 2:52 PM
    • Member
      195 point Member
    • gregw
    • Member since 08-27-2002, 5:14 AM
    • Posts 39
    I found this script on creating a custom login using forms authentication with windows authentication. The problem is its in C# and doesnt show the full code.

    Can anyone help in converting this over to VB and without a Code Behind?

    The url is, http://www.dotnetbips.com/displayarticle.aspx?id=201
  • Re: help in converting this custom login script

    08-16-2003, 12:09 AM
    • Contributor
      2,738 point Contributor
    • kashif
    • Member since 06-11-2002, 1:34 PM
    • Posts 547
    • AspNetTeam
      Moderator
    something as follows
    if (ValidateUser(txtUserID.Text,txtPassword.Text)) then
    
    FormsAuthentication.SetAuthCookie(Context.User.Identity.Name,false)
    If(Request.QueryString("ReturnUrl") is Nothing) then
    Response.Redirect("webform2.aspx")
    Else
    Response.Redirect(Request.QueryString("ReturnUrl"))
    End If
    Else
    lblError.Text="Login Failed"
    End If
    Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As [String], _
    ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
    ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
    ByRef phToken As IntPtr) As Boolean
    public SetLogin(ByVal uid as String,ByVal pwd as String) as Bool
    {
    dim token1 as int
    dim loggedOn as boolean = LogonUser(uid,".",pwd,2,0,out token1)
    dim token2 as IntPtr = new IntPtr(token1)
    dim wi as WindowsIdentity = new WindowsIdentity(token2)
    dim wp as WindowsPrincipal = new WindowsPrincipal(wi)
    HttpContext.Current.User = wp
    return true
    }
    Hope that helps
    Kashif
  • Re: help in converting this custom login script

    08-18-2003, 8:20 AM
    • Member
      195 point Member
    • gregw
    • Member since 08-27-2002, 5:14 AM
    • Posts 39
    I cant get it work. If you notice there is no ValidateUser function defined. I guessed he was refering to the SetLogin function, but i get Compilation Errors when i try to run it and so far have been unable get it to work. Still seems like part of its in C# format.

    Id like to get this to work and get rid of the windows pop up box, if anyone can help.

    thanks.
  • Re: help in converting this custom login script

    08-18-2003, 10:29 AM
    • Member
      195 point Member
    • gregw
    • Member since 08-27-2002, 5:14 AM
    • Posts 39
    with the help of another article i found, i now have the following. It runs without an errors, but always returns "Invalid Credentials: Please try again." Any thoughts on the problem?


    <script language="C#" runat=server>
    [DllImport("advapi32.dll", CharSet=CharSet.Auto)]
    public static extern int LogonUser(String lpszUserName,
    String lpszDomain,
    String lpszPassword,
    int dwLogonType,
    int dwLogonProvider,
    ref IntPtr phToken);

    public const int LOGON32_LOGON_INTERACTIVE = 2;
    public const int LOGON32_PROVIDER_DEFAULT = 0;

    void Login_Click(Object sender, EventArgs E)
    {
    IntPtr token = IntPtr.Zero;

    if(LogonUser(UserName.Value,
    UserDomain.Value,
    UserPass.Value,
    LOGON32_LOGON_INTERACTIVE,
    LOGON32_PROVIDER_DEFAULT,
    ref token) != 0)
    {
    FormsAuthentication.RedirectFromLoginPage(UserName.Value,
    PersistCookie.Checked);
    }
    else
    {
    lblResults.Text = "Invalid Credentials: Please try again";
    }
    }
    </script>

Page 1 of 1 (4 items)