PDA

View Full Version : [CODE] !Login (help wanted)


Fire_optikz001
21st September 2009, 22:20
i think i might have a bug some where could some one help? it all works but the admin pass part any idea?
CASE "!login":
IF( UserInGroup( "register" ,"Registered" ) == 1 )
THEN
IF( UserInGroup( "admin",$userName ) == 1 || UserInGroup( "beta",$userName ) == 1)
THEN
openPrivTextButton( "LUser1",50,25,25,15,5,96,"Username","Username",50,LUser);
openPrivTextButton( "LPass1",50,51,25,15,5,96,"Password","Password",30,LPass);
openPrivTextButton( "LAPass",50,76,25,15,5,96,"Admin Password","Admin Password",30,LAPass);
openPrivButton( "Login",50,101,25,15,5,-1,96,"Login",Login);
ELSE
openPrivTextButton( "LUser",50,25,25,15,5,96,"Username","Username",30,LUser);
openPrivTextButton( "LPass",50,51,25,15,5,96,"Password","Password",30,LPass);
openPrivButton( "Login",50,101,25,15,5,-1,96,"Login",Login);
ENDIF
Else
privMsg( "^1Your Not Registered");
ENDIF
BREAK;


CASE "!register":
IF( UserInGroup( "register" ,"Registered" ) != 1 )
THEN
openPrivTextButton( "RUser",50,25,25,15,5,96,"Username","Username",30,User);
openPrivTextButton( "RPass",50,51,25,15,5,96,"Password","Password",30,Pass);
MoveUserToGroup( "register" , "Registered" );
SaveGroupToFile( $userName, "./../user/registered/" . $userName . ".txt" );
Else
privMsg( "^1Already Registered");
ENDIF
BREAK;


Sub User( $User )
ClosePrivButton("RUser");
$userName = GetCurrentPlayerVar("UserName");
MoveUserToGroup( "register" , "UserName = " . $User );
SaveGroupToFile( "register" , "./../user/registered/" . $userName . ".txt" );
RemoveUserFromGroup( "register" , "UserName = " . $User );
EndSub

Sub Pass( $Pass )
ClosePrivButton("RPass");
$userName = GetCurrentPlayerVar("UserName");
MoveUserToGroup( "register" , "Password = " . $Pass );
SaveGroupToFile( "register" , "./../user/registered/" . $userName . ".txt" );
RemoveUserFromGroup( "register" , "Password = " . $Pass );
EndSub

Sub LUser( $LUser )
GlobalVar $LUser1;
$LUser1 = $LUser;
EndSub

Sub LPass( $LPass )
GlobalVar $LPass1;
$LPass1 = $LPass;
EndSub
Sub LAPass( $LAPass )
GlobalVar $LAPass1;
$LPass1 = $LAPass;

EndSub

Sub Login( $KeyFlags,$id )
$userName = GetCurrentPlayerVar("UserName");
UserGroupFromFile( "register", "./../user/registered/" . $userName . ".txt" );
IF( UserInGroup( "register" , "UserName = " . $LUser1 ) == 1 && UserInGroup( "register" , "Password = " . $LPass1 ) == 1 )
THEN
IF( $LAPass1 == $AdminPass || $LAPass1 == $BetaPass )
THEN
privMsg( "^2Thank you for logging in Admin");
MoveUserToGroup( "tempadmin",$userName );
ELSE
IF( $LAPass1 == "" )
THEN
closePrivButton("LUser1");
closePrivButton("LPass1");
privMsg( "^2Thank You For Logging In" );
closePrivButton("LAPass");
closePrivButton("Login");
ELSE
privMsg( "^1Incorrect Admin Password");
ENDIF
ENDIF
ELSE
privMsg( "Incorrect UserName And/Or Password" );
ENDIF
EndSub

Krayy
21st September 2009, 23:50
Oh, where to begin....

Firstly you are calling the UserInGroup function in both the !register and !login commands with no username. Instead of calling it like:
UserInGroup( "register" ,"Registered" )
you should probably be calling it like:
UserInGroup( "register",$UserName )

Next, in the LUser, LPass and LAPass subs, you are setting a global var to store the login/passwords which is a bit of a no-no in that anyone who runs the !login command while another is doing it might overwriet those values before they are finished with. If I were you, I would use the SetUserStoredValue and GetUserStoredValue functions to store those values in the local databse for easy retrieval later on. They can be cleared when the user logs out or disconnects, or leave them there for future reference. In fact, I would be inclined to stire them there permanently rather than trying to create a usergroup for passwords and writing it out to a text file. Syntax for those functions are:
SetUserStoredValue(LUser, $LUser);
SetUserStoredValue(LPass, $LPass);

Then they are in the storedvalues.dbs database and will be easily retreivable using:
$LUser = GetUserStoredValue(LUser);
$LPass = GetUserStoredValue(LPass);

PS: What is the LAPass setting meant to do?

Fire_optikz001
22nd September 2009, 01:16
Oh, where to begin....

Firstly you are calling the UserInGroup function in both the !register and !login commands with no username. Instead of calling it like:
UserInGroup( "register" ,"Registered" )you should probably be calling it like:
UserInGroup( "register",$UserName )Next, in the LUser, LPass and LAPass subs, you are setting a global var to store the login/passwords which is a bit of a no-no in that anyone who runs the !login command while another is doing it might overwriet those values before they are finished with. If I were you, I would use the SetUserStoredValue and GetUserStoredValue functions to store those values in the local databse for easy retrieval later on. They can be cleared when the user logs out or disconnects, or leave them there for future reference. In fact, I would be inclined to stire them there permanently rather than trying to create a usergroup for passwords and writing it out to a text file. Syntax for those functions are:
SetUserStoredValue(LUser, $LUser);
SetUserStoredValue(LPass, $LPass);Then they are in the storedvalues.dbs database and will be easily retreivable using:
$LUser = GetUserStoredValue(LUser);
$LPass = GetUserStoredValue(LPass);PS: What is the LAPass setting meant to do?


well could u do it for me? im abit confused with that stuff

and my buf is in the admin part every thing else works and im also adding a part when 2 people cant login at the same time

Krayy
22nd September 2009, 11:10
I'll get you started, but te tack that I will take is slightly to the left of yours.

Firstly, you won't need to store the username, as I said in the other thread, as the LFS username is unique o each installation and if someone is that desperate to try and hack an LFS server, then they have more time than good sense.

The admin password is already handled in the admin usergroup functions so I can't see why you want to authenticate that twice.

The user password is another matter, but the way which it should be initiated would be more logical to call the login function from within the OnConnect function. That way, you're making it compulsory to log in each time you connect. The code below will store the user password in the storedvalues database, but I will leave it to you to figure out how to get it in there.

So to summarise....put a call to OnConnect_Login at the end of the OnConnect function in the main lapper file. This will allow the user to enter his/her password and store it in the storedvalues database in the LPassTemp entry. When you click the Login button, it will check that the LPassTemp value is the same as the store LPass value. Then you're in.

That should be enough to get you started

Sub OnConnect_Login()
$UserName = GetCurrentPlayerVar("UserName");
IF ( UserInGroup( "register", $UserName ) == 1 )
THEN
openPrivTextButton( "LPass1",50,51,25,15,5,96,"Password","Password",30,LPass);
openPrivButton( "Login",50,101,25,15,5,-1,96,"Login",Login);
ELSE
privMsg( "^1You're Not Registered");
ENDIF
EndSub

Sub LPass( $LPass )
SetUserStoredValue(LPassTemp, $LPass);
TextPrivButton( "Login","^3***********" );
EndSub

Sub Login( $KeyFlags,$id )
$userName = GetCurrentPlayerVar("UserName");
IF ( GetUserStoredValue(LPass) == GetUserStoredValue(LPassTemp) )
THEN
closePrivButton("LUser1");
closePrivButton("LPass1");
privMsg( "^2Thank You For Logging In" );
closePrivButton("LAPass");
closePrivButton("Login");
ELSE
privMsg( "Incorrect Password" );
ENDIF
EndSub

Fire_optikz001
22nd September 2009, 21:31
ok but how do i set up store values aka register?

like what is the thing i dont need u to do the whole thing just that 1 line

Krayy
22nd September 2009, 22:16
ok but how do i set up store values aka register?

like what is the thing i dont need u to do the whole thing just that 1 line
UserGroupFromFile( "register", "./registered.txt" );

Fire_optikz001
22nd September 2009, 23:12
UserGroupFromFile( "register", "./registered.txt" );
ye but how do i store the values :S

Tim NL
23rd September 2009, 08:52
ye but how do i store the values :S

Hi,
You can use this to write and read to the StoredValue database.

(example)
SetUserStoredValue( "LPass" , $LPass); #write to StoredValue database
getUserStoredValue( "LPass," ); #read from StoredValue database

Works the same in the point system.

# read from database and store in playerVar
Line 59 SetCurrentPlayerVar( "ps_points_total",getUserStoredValue( "ps_points_total" ) );
# write the value from playervar into the database
Line 162 setUserStoredValue( "ps_points_total", GetCurrentPlayerVar( "ps_points_total" ) );

Fire_optikz001
25th September 2009, 22:02
im gonna make something new :)

Fire_optikz001
3rd October 2009, 19:11
if some one was nice could they post how this actually should be done :|

cause there would have to be some sort of prvention sys from people using other peopls usernames and pass words

LFSCruise
30th September 2011, 01:11
getUserStoredValue( "LPass," ); #read from StoredValue database



Required here is the comma?

Tim NL
1st October 2011, 18:23
nope is typo :shy:

must be
getUserStoredValue( "LPass,$LPass" ); #read from StoredValue database