KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Creating a Web Realm for a Web connection to 4D
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: January 24, 2003

Compatibility: Version 6.7 and 6.8


Web Realms are often used to protect an unauthorized user from accessing a specific area of your Web site. This feature is not included in 4D but you can implement a routine or a procedure that will be executed from the On Web Authentication database method and that will handle your realms.

Suppose you save three realms entries in a text array <>atRealmName and its realm condition in <>atRealmsCond,

ARRAY TEXT(<>atRealmName;3) ` Match String
<>atRealmName{1}:="Private"
<>atRealmName{2}:="Admin"
<>atRealmName{3}:=".Member"

ARRAY TEXT(<>atRealmsCond;3) ` Condition
<>atRealmsCond{1}:="Begins with"
<>atRealmsCond{2}:="Contains"
<>atRealmsCond{3}:="Ends with"

You can implement the following routine in the On Web Authentication method that will check every Web request for a specific realm.

` Database Method: On Web Authentication

C_TEXT($1;$2;$3;$4;$5;$6)

$0:=True
C_LONGINT($maxRealm;$len;$foundAt;$startAt)
$maxRealm:=Size of array(<>atRealmName)
For ($i;1;$maxRealm)
 Case of
 : (<>atRealmsCond{$i}="Begins with")
  $len:=Length(<>atRealmName{$i})
  If (<>atRealmName{$i}=Substring($1;1;$len))
  If (IsAllowedAccount ($5;$6)) ` Returns true if the username and password is correct
   $0:=True
  Else
  $i:=$maxRealm+1
  $0:=False
  End if
 End if

: (<>atRealmsCond{$i}="Contains")
 $foundAt:=Position(<>atRealmName{$i};$1)
 If ($foundAt>0)
  If (IsAllowedAccount ($5;$6)) ` Returns true if the username and password is correct
  $0:=True
  Else
   $i:=$maxRealm+1
  $0:=False
 End if
End if


 : (<>atRealmsCond{$i}="Ends with")
 $startAt:=Length(<>atRealmName{$i})
 $len:=Length($1)
 If ($startAt<$len)
  If (<>atRealmName{$i}=Substring($1;($len-$startAt)+1;$len))
   If (IsAllowedAccount ($5;$6)) ` Returns true if the username and password is correct
   $0:=True
  Else
   $i:=$maxRealm+1
  $0:=False
  End if
 End if
End if


 End case
End for