Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help Making a Simple Login Script

Help Making a Simple Login Script

         

lindajames

4:05 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



Hi there,

I am hosting multiple websites, and each website has webmail access by going to [webmail.domainname.com...]

basically i want to setup a perl script that will allow me to let users login to their webmail through my site.

If users goto webmail.theirdomain.com they are presented with a login page that has the following type of login form:

<form action="login.php" method="post" name="login">
<input type="text" size="25" name="username"><br>
<input type="password" size="25" name="password">
<input type="hidden" name="server_id" value="0">
<input type="hidden" name="template" value="style1">
<input type="hidden" name="language" value="en">
<input type="submit" name="submit" value="Login">
</form>

Basically, i want to make a script that will ask the user for their email address and password, and using that information it logs them onto the relavant domain's webmail. So basically, if the user enters linda@mydomain.com, the perl script should set the login form action to [webmail.mydomain.com...] and the username should be set to linda and the password should be same.

Can anyone help me make such a script?

Any help would be much appreciated.

Cheers
Linda

jatar_k

6:58 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just checking, you say perl script but then you refer to login.php.

It is perl you are looking for is it not?

serves as a bump too ;)

dmorison

7:51 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Linda,

The webmail client you are using - your requirements say that is must be logged into using just "linda" and the password.

Do you know if it works if you try and login using the full email address, even though you _don't_ need to? Most email clients are reasonably clever like that. It's the same way that most ISP's will accept either "username" or "username@domain.com" as your username.

First see if that works. If it does, then I think your easiest solution is on your common login script (login.pl?) you inspect the email address to figure out which domain name they're from.

If the email address is linda@foo.com, you would extract foo.com. I don't do Perl, but i'm sure extracting the part after the '@' from a string is easy.

So you've extracted "foo.com". Concat this together with "http://webmail." and "/login.php", giving you "http://webmail.foo.com/login.php", and send the browser a 302 (page moved) to this new location.

The browser should then re-post the form to the users appropriate webmail login script.. :)

Cheers!

PS: If you discover that your webmail system doesn't like the full email address as the username, do you have access to login.php so that you can hack it so that it does?

dmorison

9:24 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By the way,

I've not tested this and i'm making the assumption that 302 (page moved) is a valid reponse to a POST operation and can be handled by browsers ok....

Might be worth checking up with the specs. It's the sort of thing I would imagine Internet Explorer being okay about even if it's not in the specs :)

lindajames

11:20 am on Apr 20, 2003 (gmt 0)

10+ Year Member



Basically, i want to present users with a html form with 2 fields, field 1 will be email and field 2 will be password. So basically, i want a perl script to take the domain of the email address in other words everything after the @ sign and i want to set it as a variable so that i can use it in the script i.e. domain: $domain and i also need the script to take everything before the @ sign and store that as a variable aswell.

using these variables i will create a page with hidden fields and then i will use an onload="document.login.submit();" in order to log the user in their webmail

Any suggestions would be much appreciated.

Cheers
Linda

dmorison

12:00 pm on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Linda,

Did you try the 302 solution? It does work, but a GG search reveals some quirks so I wouldn't risk it.

Anyway, if you're going to use JavaScript, why not just do the whole thing client side in JavaScript?

One reason for coming back to your server would of course be to veryify that the domain extracted from the email address is one of yours....

dmorison

12:07 pm on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here ya go...

<script type='text/javascript'>

function doSubmit()
{
var s = document.login.username.value;

var p = s.indexOf('@');

var d = s.substring(p + 1, s.length);

var u = s.substring(0, p);

document.login.username.value = u;

document.login.action = 'http://webmail.'+d+'/login.php';

document.login.submit();
}
</script>

<form name="login" method="post" action="">

Email Address: <input type="text" name="username"><br>

Password: <input type="password" name="password"><br>

<input type="hidden" name="server_id" value="0">

<input type="hidden" name="template" value="style1">

<input type="hidden" name="language" value="en">

<input type='button' value='Login' onclick='javascript:doSubmit();'>

</form>

lindajames

1:04 pm on Apr 20, 2003 (gmt 0)

10+ Year Member



thanx dmorison,

seems to have done the trick, but one quick question, any chance of telling me how i can validate the email address to make sure they put a valid email address with an @something.com .net etc. email address?

thanx again.

linda

dmorison

6:44 pm on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could do a simple check for the @ character by testing "p" for the value of -1 in the code...

var p = s.indexOf('@');

if (p == -1)
{
alert('Please enter a valid email address.');
}
else
{
var d = s.substring(p + 1, s.length);

var u = s.substring(0, p);

document.login.username.value = u;

document.login.action = 'http://webmail.'+d+'/login.php';

document.login.submit();
}

Other than that, you can of course go a step further and check "d" for ".com" or ".net" etc, or ultimately go all the way and check "d" against all the domains for which you offer webhosting...