Jump to content

Simple Registration


Micheck

Recommended Posts


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   8
  • Joined:  11/24/17
  • Last Seen:  

Simple Registration HTML+PHP (v1.0)

The HTML is very basic and is intended to use for server admin in production environment. It just have a SignUp and Login function. Fill up the server info in dbh.inc.php and you are good to go.

The PhP script had been optimized for live webserver, below is the information :

  • SQL injection protected (please test and reply to me)
  • using 'prepared-statement
  • using bind_param
  • login function using 'SESION'

Please test the script and any comment is welcome. I will update the script from time to time. Thank you.

Sorry for my english

 

Edited by Micheck
edit the link to the file
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  1137
  • Reputation:   290
  • Joined:  04/29/13
  • Last Seen:  

Submit your file here

https://rathena.org/board/files/

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   8
  • Joined:  11/24/17
  • Last Seen:  

@Cyro i have put at the correct sections, sorry as this is my first time posting here.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

/*//De-hashing the password (use this if password is hashed)
$hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
if ($hashedPwdCheck == false) {
header("Location: ../index.php?login=error");
exit();
}*/

The password check is completely disabled, so currently you need to send a password which is >= 1 and you're able to log in with any account.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   8
  • Joined:  11/24/17
  • Last Seen:  

@Jey oopss... yes i made a mistake there, i will rectify it now. That is due i disable the hashed password as i do not know rathena login system can use it or not?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

If I may give some more feedback:


	if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
		header("Location: ../signup.php?signup=empty");
		exit();
	} else {
		//Check if input characters are valid
		if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last) || !preg_match("/^[1-9][0-9]*$/", $gid)) {
			header("Location: ../signup.php?signup=invalid");
			exit();
		} else {
			//Check if email is valid
			if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
				header("Location: ../signup.php?signup=email");
				exit();
			} else {
				//Check if username exists USING PREPARED STATEMENTS
				$sql = "SELECT * FROM login WHERE userid=?";
				//Create a prepared statement
				$stmt = mysqli_stmt_init($conn);
				//Check if prepared statement fails
				if(!mysqli_stmt_prepare($stmt, $sql)) {
				    header("Location: ../index.php?login=error");
				    exit();
				} else {
					//Bind parameters to the placeholder

This nesting makes the code look pretty bad, try to use more functions, classes and their methods to make the code more readable.

For example these prepared statements could be used like objects `$stmt->bindParam(1$name);`

Rathena is currently able to hash passwords with md5.

 

Edit: But I like the usage of regex to validate the user input.

Edited by Jey
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   8
  • Joined:  11/24/17
  • Last Seen:  

1 hour ago, Jey said:

If I may give some more feedback:



	if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
		header("Location: ../signup.php?signup=empty");
		exit();
	} else {
		//Check if input characters are valid
		if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last) || !preg_match("/^[1-9][0-9]*$/", $gid)) {
			header("Location: ../signup.php?signup=invalid");
			exit();
		} else {
			//Check if email is valid
			if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
				header("Location: ../signup.php?signup=email");
				exit();
			} else {
				//Check if username exists USING PREPARED STATEMENTS
				$sql = "SELECT * FROM login WHERE userid=?";
				//Create a prepared statement
				$stmt = mysqli_stmt_init($conn);
				//Check if prepared statement fails
				if(!mysqli_stmt_prepare($stmt, $sql)) {
				    header("Location: ../index.php?login=error");
				    exit();
				} else {
					//Bind parameters to the placeholder

This nesting makes the code look pretty bad, try to use more functions, classes and their methods to make the code more readable.

For example these prepared statements could be used like objects `$stmt->bindParam(1$name);`

Rathena is currently able to hash passwords with md5.

Thank you for the feedback @Jey i appreciated it , i will improve the nesting. I am learning prepared statement now in school, so that is why i am making this script to test what have i learned.

@Jey , is using prepared statements for this kind of script is good or without it will works better?

Anyways, i will try to rectify the login. Thank you again jey

Edited by Micheck
asking questions to jey
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

https://en.wikipedia.org/wiki/Prepared_statement

I'd prefer prepared statements in 95% of all cases, since they're resilient against sql injection and they're quicker if they are executed repeatedly. Keep on implementing stuff, you will get better the more code you write and read. Especially with some feedback :)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   8
  • Joined:  11/24/17
  • Last Seen:  

I have update the code. It is not using prepared statements now as i need to learn more about that :( 

Below is the change log for the new versions :

v1.0.1

  • using 'prepared-statement
  • login should work now
  • MD5 supported
  • update regular expressions so it match to the correct value
  • fix typo on GID regex
Edited by Micheck
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  84
  • Topics Per Day:  0.02
  • Content Count:  309
  • Reputation:   82
  • Joined:  11/15/11
  • Last Seen:  

Link off?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   8
  • Joined:  11/24/17
  • Last Seen:  

4 hours ago, Windows XP said:

Link off?

Still pending approval.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  249
  • Reputation:   72
  • Joined:  10/20/12
  • Last Seen:  

Mh... I'm not really sure if this really belongs to file releases. I don't think anyone is in need of a login system without an associated web site :D

You could post these things under script/source support. Or if you feel confident you could try to improve rathenas FluxCP on our github page by submitting pull requests. Help is highly appreciated there, but keep in mind that your code must fulfill high standards, so doing small issues/additions first will help you to get into it and help us to know you and your code style better :)

Edit: https://github.com/rathena/FluxCP

Note: Akkarin is currently more or less the only one, who is maintaining the FluxCP. Most of the rathena devs are working on the emulator itself. So it would be nice to have another active person there.

Edited by Jey
  • Upvote 2
Link to comment
Share on other sites

×
×
  • Create New...