Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating auth_user

Status
Not open for further replies.

Webflex

Technical User
Apr 20, 2001
101
GB
Hi

I have 2 separate form fields

user

and

domain

that I would like to populate with values from

Code:
<%= &quot;&quot; & request.servervariables(&quot;auth_user&quot;)%>

I'm not sure how to

1. Write the value to the form field

and

2. Split the variable to place each part of domain\user in the appropriate box.

Any help much appreciated

TIA
Webflex
 
I've never seen a AUTH_USER string but
suppose the AUTH_USER string is like an email address username@domain .

In Javascript use the indexOf() method to find the @ position and use the substring() method to break out the two parts.
Code:
var au = Request.ServerVariables(&quot;AUTH_USER&quot;).value;
atPosition = au.indexOf(&quot;@&quot;);
var userPiece = au.substring(0,atPosition);var domainPiece = au.substring(atPosition+1, au.length);

Populate the input text field using Response.Write for the value attribute.
Code:
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;user&quot; VALUE=&quot;<%= userPiece %>&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;domain&quot; VALUE=&quot;<%= domainPiece %>&quot;>

Hope this helps.
 
Thanks, I'm trying this out (in an .asp page) in this format,

Code:
<html>

<head>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var au = Request.ServerVariables(&quot;AUTH_USER&quot;).value; 
atPosition = au.indexOf(&quot;\&quot;);
var userPiece = au.substring(0,atPosition);
var domainPiece = au.substring(atPosition+1, au.length);
</script>

<title>Auth User</title>
</head>

<body>



<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;user&quot; VALUE=&quot;<%= userPiece %>&quot; size=&quot;20&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;domain&quot; VALUE=&quot;<%= domainPiece %>&quot; size=&quot;20&quot;>

</body>

</html>

the separator for domain\username is the backslash which keeps generating unterminated string contstants, what's the best way round this.

Another problem if i change the backslash \ to at @ is this

Code:
var au = Request.ServerVariables(&quot;AUTH_USER&quot;).value;

generates an error telling me 'Request' is undefined.

As you may have guessed I'm on a steep learning curve here :>)
 
First, I think I may have confused things by refering to Javascript. I meant that I use JScript instead of VBScript with ASP. So the code is part of the ASP script, not a <SCRIPT></script> on the HTML page.

Code:
<%
var au = Request.ServerVariables(&quot;AUTH_USER&quot;).value;
var atPosition = au.indexOf(&quot;\\&quot;);
var userPiece = au.substring(0,atPosition);
var domainPiece = au.substring(atPosition+1, au.length);
%>

Then, the backslash is used in JScript as part of an escape sequence when refering to special characters like quote marks and, yes, backslashes. So search for &quot;\\&quot; as shown above instead of &quot;\&quot;.

Putting the code in the ASP script will eliminate the error message too since Request is defined in ASP but not in Javascript.

Sorry to give a confusing answer.
 
Try this using VB Script. No JavaScript needed. It's untested, so you may need to tweek a little. Assumes the userPiece is to the left and the domainPiece is to the right of the backslash.
<%
dim authuser
dim slashpos
dim userPiece
dim domainPiece

authuser = Request.ServerVariables(&quot;AUTH_USER&quot;)
slashpos = instr(authuser,&quot;\&quot;)

userPiece = Left(authuser,slashpos - 1)
domainPiece = Right(authuser,Len(authuser) - slashpos)
%>



<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;user&quot; VALUE=&quot;<%=userPiece%>&quot; size=&quot;20&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;domain&quot; VALUE=&quot;<%=domainPiece%>&quot; size=&quot;20&quot;>

Let me know if it works.

TW
 
Guys

Thanks for the replies

Rac2, your code gives me this

Code:
Microsoft VBScript compilation error '800a0401' 

Expected end of statement 

/nfuse/asp/user2.asp, line 2 

var au = Request.ServerVariables(&quot;AUTH_USER&quot;).value;
---------------------------------------------------^

ToddWW

This is the response from your code

Code:
Microsoft VBScript runtime error '800a0005' 

Invalid procedure call or argument: 'Left' 

/nfuse/asp/user.asp, line 10

the domain piece is on the left but I just amended the code as follows

Code:
<%
dim authuser
dim slashpos
dim domainPiece
dim userPiece

authuser = Request.ServerVariables(&quot;AUTH_USER&quot;)
slashpos = instr(authuser,&quot;\&quot;)

domainPiece = Left(authuser,slashpos - 1)
userPiece = Right(authuser,Len(authuser) - slashpos)
%>



<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;user&quot; VALUE=&quot;<%=userPiece%>&quot; size=&quot;20&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;domain&quot; VALUE=&quot;<%=domainPiece%>&quot; size=&quot;20&quot;>

I guess from the time of your posts on Friday that you are in a USA time zone (I'm in the UK), I will be trying to troubleshoot these further later on so if i make progress I'll post here.

Many thanks
Webflex
 
Have not managed to make any further progress :<(
 
Hmm... Try this. If that doesn't work, I'll put it on my machine and trouble shoot it.

slashpos = CInt(instr(authuser,&quot;\&quot;))


TW
 
Code:
<%
dim authuser
dim slashpos
dim domainPiece
dim userPiece

authuser = Request.ServerVariables(&quot;AUTH_USER&quot;)
slashpos = CInt(instr(authuser,&quot;\&quot;))

domainPiece = Left(authuser,slashpos - 1)
userPiece = Right(authuser,Len(authuser) - slashpos)
%>



<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;user&quot; VALUE=&quot;<%=userPiece%>&quot; size=&quot;20&quot;>
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;domain&quot; VALUE=&quot;<%=domainPiece%>&quot; size=&quot;20&quot;>

still produces this

Code:
Microsoft VBScript runtime error '800a0005' 

Invalid procedure call or argument: 'Left' 

/nfuse/asp/user.asp, line 10

Thanks for the continuing efforts
 
Okay would someone kick me..........

The code works fine...... but it has to be on a folder that is restricted and does not have the everyone group with rights to it. Obvious really when you think about it.

Cheers
Webflex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top