Copyright: Ver 1.0
Citation: Copyright © 1996 - 2000 by Inabyte Inc. All rights reserved.


InaAuthenticate Control

InaAuthenticate is a 32-bit ATL control or NT/2000 Service for use with VB, C++, Delphi or any language that supports components.

It is an ideal tool for verifying users and the groups they belong to within NT domains via an Active Server Page.

The InaAuthenticate control contains 2 objects:

IInaAuthenticate Object

IInaUserGroups Object


IInaAuthenticate Object

The IInaAuthenticate object allows for checking that a user exists within a domain.


Check Method (IInaAuthenticate Object)

Returns a BOOL

Syntax

VB

Object.Check(strDomain, strUser, strPassword)

C++

BOOL Object.Check(_bstr_t pDomain, _bstr_t pUser, _bstr_t pPassword)

Part
Description
Object
An object expression that evaluates to a IInaAuthenticate object.
Domain
A string expression that represents the domain to authenticate against.
User
A string expression that represents the user name.
Password
A string expression that represents the user password.
Remarks

This method is for authenticating a user.

Example

VB

Private Sub btnClose_Click()

    Unload Me

End Sub

Private Sub btnExecute_Click()

    Dim Auth As InaAuthenticate

    Dim Group As Variant

    Set Auth = CreateObject("Inabyte.InaAuthenticate")

    If Auth.Check(txDomain, txUser, txPassword) Then

        If ckSHowGroups Then

            lbGroups.Clear

            For Each Group In Auth.Groups(txDomain, txUser)

                lbGroups.AddItem Group

            Next Group

        Else

            Unload Me

        End If

    Else

        MsgBox "Invalid"

    End If

    Set Auth = Nothing

End Sub

C++

bool	bValid = false;

HRESULT	hResult;

IInaAuthenticatePtr	pAuth;

hResult = pAuth.CreateInstance("Inabyte.InaAuthenticate");

if (hResult == S_OK)

bValid = pAuth->Check((LPCTSTR)m_Domain, (LPCTSTR)m_User, (LPCTSTR)m_Password) != VARIANT_FALSE;

else

{

AfxMessageBox(hResult == E_ACCESSDENIED ? "Evaluation Expired" : "Control not registered");

return;

}

if (!bValid)

{

AfxMessageBox("Failed to authenticate", MB_OK);

return;

}


IInaUserGroups Object

The IInaUserGroups object allows for details about user groups.


InGroup Method (IInaUserGroups Object)

Returns a BOOL

Syntax

VB

Object.InGroup(strDomain, strUser, strGroup)

C++

BOOL Object.InGroup(_bstr_t pDomain, _bstr_t pUser, _bstr_t pGroup)

Part
Description
Object
An
object expression
 that evaluates to a IInaUserGroups object.
Domain
A
string
 expression that represents the domain to authenticate against.
User
A
string
 expression that represents the user name.
Group
A
string
 expression that represents the group being checked.
Remarks

This method is used for checking if a user belongs to a group within a domain.

Example

VB

Private Sub btnExecute_Click()

    Dim Auth As InaAuthenticate

    Dim Group As Variant

    Set Auth = CreateObject("Inabyte.InaAuthenticate")

    If Auth.Check(txDomain, txUser, txPassword) Then

        If Not Auth.InGroup(txDomain, txUser, txGroup) Then

MsgBox "Not in group"

        End If

    Else

        MsgBox "Invalid "

    End If

    Set Auth = Nothing

End Sub

C++

bool	bValid = false;

HRESULT	hResult;

IInaAuthenticatePtr	pAuth;

hResult = pAuth.CreateInstance("Inabyte.InaUserGroups");

if (hResult == S_OK)

bValid = pAuth->Check((LPCTSTR)m_Domain, (LPCTSTR)m_User, (LPCTSTR)m_Password) != VARIANT_FALSE;

else

{

AfxMessageBox(hResult == E_ACCESSDENIED ? "Evaluation Expired" : "Control not registered");

return;

}

if (!bValid)

{

AfxMessageBox("Failed to authenticate", MB_OK);

return;

}

else

{

bValid = IInaUserGroupsPtr(pAuth)->InGroup((LPCTSTR)m_Domain, (LPCTSTR)m_User, (LPCTSTR)m_Group);

if (!bValid)

{

AfxMessageBox("User not in group", MB_OK);

return;

}

}


Groups Method (IInaUserGroups Object)

Returns a variant.

Syntax

VB

Variant = Object.Groups(strDomain, strUser)

C++

_variant_t Object.Groups(_bstr_t pDomain, _bstr_t pUser)

Part
Description
Object
An
object expression
 that evaluates to a IInaUserGroups object.
Domain
A
string
 expression that represents the domain to authenticate against.
User
A
string
 expression that represents the user name.
Remarks

This method is for obtaining all the groups a user belongs to.

Example

VB

Private Sub btnClose_Click()

    Unload Me

End Sub

Private Sub btnExecute_Click()

    Dim Auth As InaAuthenticate

    Dim Group As Variant

    Set Auth = CreateObject("Inabyte.InaAuthenticate")

    If Auth.Check(txDomain, txUser, txPassword) Then

        If ckSHowGroups Then

            lbGroups.Clear

            For Each Group In Auth.Groups(txDomain, txUser)

                lbGroups.AddItem Group

            Next Group

        Else

            Unload Me

        End If

    Else

        MsgBox "Invalid"

    End If

    Set Auth = Nothing

End Sub

C++

bool	bValid = false;

HRESULT	hResult;

IInaAuthenticatePtr	pAuth;

hResult = pAuth.CreateInstance("Inabyte.InaUserGroups");

if (hResult == S_OK)

bValid = pAuth->Check((LPCTSTR)m_Domain, (LPCTSTR)m_User, (LPCTSTR)m_Password) != VARIANT_FALSE;

else

{

AfxMessageBox(hResult == E_ACCESSDENIED ? "Evaluation Expired" : "Control not registered");

return;

}

if (!bValid)

{

AfxMessageBox("Failed to authenticate", MB_OK);

return;

}

else

{

_variant_t	vGroup;

long	lIndex;

long	lUpperBound;

variant_t	vValue = IInaUserGroupsPtr(pAuth)->Groups((LPCTSTR)m_Domain, (LPCTSTR)m_User);

if (vValue.vt == (VT_ARRAY | VT_VARIANT) && SUCCEEDED(SafeArrayGetLBound(vValue.parray, 1, &lIndex)) && SUCCEEDED(SafeArrayGetUBound(vValue.parray, 1, &lUpperBound)))

{

m_GroupsListBox.ResetContent();

for ( ; lIndex <= lUpperBound && SUCCEEDED(SafeArrayGetElement(vValue.parray, &lIndex, &vGroup)); ++lIndex)

{

m_GroupsListBox.AddString((_bstr_t)vGroup);

vGroup.Clear();

}

}

}


Example (ASP)

<%@ LANGUAGE="VBSCRIPT"%>

<%Option Explicit%>

<!--#include File="../adovbs.inc"-->

<%

Dim strMainPrompt

Dim strError

Dim strUser, strPassword

If Request.Form("ValidationReq") = 1 Then

strUser = Request.Form("user")

strPassword = Request.Form("password")

DoLoginCheck()

End If

Sub DoLoginCheck

    Dim AuthObject

    Dim valid

    Dim strGroups

    Dim strGroup

strGroups = ""

    Set AuthObject = CreateObject("Inabyte.InaAuthenticate")

    valid = AuthObject.Check("mydomain", strUser, strPassword)

    If valid Then

valid = AuthObject.InGroup("mydomain", strUser, "DomainUsersGroup")

    Else

strError = "Invalid user or password"

Exit Sub

    End If

    If valid Then

For Each strGroup In AuthObject.Groups("mydomain", strUser)

        	strGroups = strGroups + strGroup + ";"

    	Next

    Else

strError = "Not authenticated for this page"

Exit Sub

    End If

    Set AuthObject = Nothing

    If valid Then

Response.Redirect("mainmenu.asp")

Response.End

    Else

strError = "Invalid user or password"

Exit Sub

    End If

End Sub

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="GENERATOR" content="Microsoft FrontPage 3.0">

<title>default</title>

</head>

<body bgcolor="#ffffff" topmargin=0 leftmargin=0>

<p align="left"><%=strMainPrompt%></p>

<form action="default.asp" method="post" name="form" language="JavaScript"

onsubmit="return validate();">

  <input type="hidden" name="ValidationReq" value="1"><table border="0" width="100%"

  height="53">

    <tr>

      <td width="20%" valign="top" align="left" height="1"><strong>*User:</strong></td>

      <td width="3%" height="1"></td>

      <td width="77%" height="1" valign="top" align="left"><input id="user" NAME="user"

      value="<%=strUser%>" style="HEIGHT: 25px; LEFT: 70px; TOP: 190px; WIDTH: 223px" size="39">

      </td>

    </tr>

    <tr>

      <td width="20%" valign="top" align="left" height="1"><strong>*Password:</strong></td>

      <td width="3%" height="1"></td>

      <td width="77%" height="1" valign="top" align="left"><input id="password" name="password"

      type="password" size="20"> </td>

    </tr>

  </table>

  <p><strong><input type="submit" name="submit" value="submit" id="submit"

  style="LEFT: 10px; TOP: 244px"> </strong></p>

</form>

<p align="left"><%=strError%></p>

<!--#include File="../footer.asp"-->

<p><script language="JavaScript">

  // This function checks that the form was filled out with valid data (i.e. an integer

  // for the AccountID and a non-null string for the password)

function validate()

{

document.form.ValidationReq.value = 0;

if (isEmpty(document.form.user.value))

{

alert('Please enter a user name');

return false;

}

if (isEmpty(document.form.password.value))

{

alert('Please enter a password');

return false;

}

document.form.ValidationReq.value = 1;

return true;

}

function isEmpty(str)

{

if (str.length < 1)

return true;

return false;

}

</script> </p>

</body>

</html>


object expression

An expression that specifies a particular object. This expression can include any of the object's containers. For example, your application can contain an Application object that contains a Document object that contains a Text object.


constant

A named item that retains a constant value throughout the execution of a program, as opposed to a variable, whose value can change during execution. Each host application can define its own set of constants. Additional constants may be defined by the user with the Const statement. Constants can be used anywhere in your code in place of actual values. A constant may be a string or numeric literal, another constant, or any combination that includes arithmetic or logical operators except Is and exponentiation. For example:

Const A = "MyString"


string

A set of consecutive characters treated by a computer as a single item.