Jump to content

[PROBLEM] Change Password with Pin as Security Code


hrace009

Recommended Posts

hello everyone, i try to make a registration script and change password script with PIN as security code, registration script was working perfect, but change password script didn't work. here i give a full code for you to review. ;)

 

here link to file Test.7z

 

I hope someone can help and give me information what i'am missing.

Link to comment
Share on other sites

Why not isolate the issue and post it here rather than ask someone to download and review your entire script?

 

because it was long code on it ok i try to give full code here.

 

Register Section

index.php

<html>
<head>
<link rel="shortcut icon" href=".fav.ico">
<!--    <meta http-equiv="refresh" content="10" > -->
<title>Register</title>
</head>
<body style="margin: 0 padding: 0;" bgcolor="black">
<?
include "config.php";
?>
<p align=center><a href="http://www.hrace009.net"><font color=white><b>GUIDE</b></font></a></p>
<table width="95%" height="95%" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
    <td align="center" valign="top">
    <?
    $Data = '<form action=index.php method=post>
     <br><br><font color=white><b>Login:</b></font>  
    <br><input type=text name=login><br><br>
     <font color=white><b>Password:</b></font>
    <br><input type=password name=passwd><br><br>
     <font color=white><b>Repeat Password:</b></font>
    <br><input type=password name=repasswd><br><br>
    <font color=white><b>Email:</b></font>
    <br><input type=text name=email><br><br>
    <font color=white><b>Pin:</b></font>
    <br><input type=password name=pin><br><br>
    <input type=submit name=submit value="Registration">
    </form>';
         
    if (isset($_POST['login']))
        {
            $Link = MySQL_Connect($DB_Host, $DB_User, $DB_Password) or die ("Can't connect to MySQL");
            MySQL_Select_Db($DB_Name, $Link) or die ("Database ".$DB_Name." do not exists.");
            
            $Login = $_POST['login'];
            $Pass = $_POST['passwd'];
            $Repass = $_POST['repasswd'];
            $Email = $_POST['email'];
     $Pin = $_POST['pin'];
            
            $Login = StrToLower(Trim($Login));
            $Pass = StrToLower(Trim($Pass));
            $Repass = StrToLower(Trim($Repass));
            $Email = Trim($Email);
            $Pin = StrToLower(Trim($Pin));
     
        if (empty($Login) || empty($Pass) || empty($Repass) || empty($Email) || empty($Email) || empty($Pin))
            {
                echo "<font color=white><b>Some fields is empty.</b></font>";
            }
         
        elseif (ereg("[^0-9a-zA-Z_-]", $Login, $Txt))
            {
                echo "Login have a incorrect format.";
            }
            
         elseif (ereg("[^0-9a-zA-Z_-]", $Pass, $Txt))
            {
                echo "Password have a incorrect format.";     
            }
         
         elseif (ereg("[^0-9a-zA-Z_-]", $Repass, $Txt))
            {
                echo "Repeat password have a incorrect format.";     
            }

        elseif (StrPos('\'', $Email))
            {
                echo "<font color=red><b>Email have a incorrect format.</b></font>";     
            }     

         elseif (ereg("[^0-9]", $Pin, $Txt))
            {
                echo "Pin have a incorrect format, Only use Numeric.";
     }

        else
            {
                $Result = MySQL_Query("SELECT name FROM users WHERE name='$Login'") or ("Can't execute query.");
                 
        if (MySQL_Num_Rows($Result))
            {
                echo "<font color=red><b>Account ".$Login." is exists</b></font>";
            }
         
        elseif ((StrLen($Login) < 4) or (StrLen($Login) > 10))  
         
            {
                echo "<font color=red><b>Login must have more 4 and not more 10 symbols.</b></font>";
            }
            
        elseif ((StrLen($Pass) < 4) or (StrLen($Pass) > 10))  
         
            {
                echo "<font color=red><b>Password must have more 4 and not more 10 symbols.</b></font>";
            }
            
        elseif ((StrLen($Repass) < 4) or (StrLen($Repass) > 10))  
            {
                echo "<font color=red><b>Repeat password must have more 4 and not more 10 symbols.</b></font>";
            }
            
        elseif ((StrLen($Email) < 4) or (StrLen($Email) > 25))  
            {
                echo "<font color=red><b>Email must have more 4 and not more 25 symbols.</b></font>";
            }

 elseif ((StrLen($Pin) < 4) or (StrLen($Pin) > 4))  
            {
                echo "<font color=red><b>Repeat Pin must have 4 digits numeric.</b></font>";
            }

        elseif ($Pass != $Repass)
            {
                echo "<font color=red><b>Password mismatch.</b></font>";
            }         
        else
            {
                $Salt = $Login.$Pass;
                $Salt = md5($Salt);
                $Salt = "0x".$Salt;
                MySQL_Query("call adduser('$Login', $Salt, '0', '0', '0', '0', '$Email', '0', '0', '0', '0', '0', '0', '0', '', '$Pin', $Salt)") or die ("Can't execute query.");
                $cash = mysql_query("SELECT * FROM users WHERE name='$Login'") or die("can't find ID");
	  $cash2 = mysql_fetch_array( $cash );
	  $id = $cash2['ID'];
	  $amount = 20000000;
                $amount *= 100;
	  MySQL_Query("call usecash ( '$id' , 1, 0, 1, 0, '$amount', 1, @error)");
	  if (MySQL_Num_Rows($cash ))
	  {
	  echo "<font color=white><b>Account</b></font> <font color=green><b>".$Login."</b></font> <font color=white><b>has been registered and free 20.000.000 Cubi-Gold.</b></font>";
	  }
	  else
	  {
                echo "<font color=white> Account</font> <font color=green><b><b>".$Login."</b></font> <font color=white>Failed try again.</font>";
	  }
            }         
        }     
    }
     
    echo $Data;
?>
<p align="center">
</p>
    </td>
</tr>
</table>
</body>
</html> 

 

config.php

<?php

    /*-------Config MySQL Database-------*/

    $DB_Host = "localhost";  // localhost or your IP
    $DB_User = "root";  // Database user
    $DB_Password = "root";  // Database password
    $DB_Name = "data";  // Database name
    $ServerIP = "192.168.0.10";  // IP your PW Server  or 127.0.0.1
    $ServerPort = "29000";  // Port your PW Server


    $db_link = mysql_connect($DB_Host, $DB_User, $DB_Password);
    $db = mysql_select_db("$DB_Name", $db_link);

    // security check for http_get variables to prevent injections
    foreach ($_GET as $key => $value)
    {
        $_GET[$key] = mysql_real_escape_string($value, $db_link);
    }
    // security check for http_get variables to prevent injections
    foreach ($_POST as $key => $value)
    {
        $_POST[$key] = mysql_real_escape_string($value, $db_link);
    }
?>

Link to comment
Share on other sites

Reset Password Section

 

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Change Password</title>
</head>

<body bgcolor="#161616">
<form name='form1' method='post' action='data.php'>
<b><font color=white>
<table width="337">
  <tr>
    <th scope="col"><div align="center"><strong>User Name</strong></div></th>
    <th scope="col"><div align="center"><strong>:</strong></div></th>
    <th scope="col">
      
        <div align="center">
          <input name='myusername' type='text' id='myusername' />
        </div></th></tr>
  <tr>
    <th scope="row"><div align="center"><strong>Email Address</strong></div></th>
    <td><div align="center"><strong>:</strong></div></td>
    <td>
      <div align="center">
        <input name='email' type='text' id='email' />
        </div></td>
  <tr>
    <th scope="row"><div align="center"><strong>Current Password</strong></div></th>
    <td><div align="center"><strong>:</strong></div></td>
    <td>
      <div align="center">
        <input name='oldpassword' type='password' id='oldpassword' />
        </div></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><strong>New Password</strong></div></th>
    <td><div align="center"><strong>:</strong></div></td>
    <td>
      <div align="center">
        <input name='newpassword' type='password' id='newpassword' />
        </div></td>
  </tr>
  <tr>
    <th scope="row"><div align="center"><strong>Confirm New Password</strong></div></th>
    <td><div align="center"><strong>:</strong></div></td>
    <td>
      <div align="center">
        <input name='confirmnew' type='password' id='confirmnew' />
        </div></td>
  </tr>
    </tr>
    <tr>
    <th scope="row"><div align="center"><strong>Pin</strong></div></th>
    <td><div align="center"><strong>:</strong></div></td>
    <td>
      <div align="center">
        <input name='pin' type='password' id='pin' />
        </div></td>
  </tr>
  <tr>
    <th colspan="3" scope="row"><div align="center">
      <input type='submit' name='Submit' value='Change Password' />
    </div></th>
  </tr>
</table>
</form>
</body>
</html>

 

data.php

<body bgcolor="#161616">
<font color=white>
<style type="text/css">
<!--
body {
background-color: #161616;
background-image: url();
background-repeat: no-repeat;
background-position: center 0;
color: white;
}
A:link {text-decoration: none; color: orange;}
A:visited {text-decoration: none; color: orange;}
A:active {text-decoration: none; color: orange;}
A:hover {text-decoration: underline overline; color: white;}
</style>
<?
require_once("DB.php");

include "connector.php";
// $dbdsn = 'mysql://root:root@localhost/dbo';
   $mysql = 'mysql://';
   $col = ':';
   $at = '@';
   $slash = '/';
   $dbdsn = $mysql.$DB_User.$col.$DB_Password.$at.$DB_Host.$slash.$DB_Name;

$dbh =& DB::connect($dbdsn);
if (PEAR::isError($dbh)) {
die($dbh->getMessage());
}
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);

$UserName=$_POST['myusername']; 
$EMail=$_POST['email'];
$OldPassword=$_POST['oldpassword'];
$NewPassword=$_POST['newpassword'];
$ConfirmNew=$_POST['confirmnew'];
$Pin=$_POST['pin'];

$UserName = stripslashes(StrToLower($UserName));
$EMail = stripslashes(StrToLower($EMail));
$OldPassword = stripslashes($OldPassword);
$NewPassword = stripslashes($NewPassword);
$ConfirmNew = stripslashes($ConfirmNew);
$Pin = stripslashes($Pin);

$UserName = mysql_real_escape_string($UserName);
// $EMail = mysql_real_escape_string($EMail);
$OldPassword = mysql_real_escape_string($OldPassword);
$NewPassword = mysql_real_escape_string($NewPassword);
// $ConfirmNew = mysql_real_escape_string($ConfirmNew);
$Pin = mysql_real_escape_string($Pin);

        if (empty($UserName) || empty($EMail) || empty($OldPassword) || empty($NewPassword) || empty($ConfirmNew) || empty($OldPassword))
            {
                echo "<font color=red>One or more fields are empty.</font><br><input type='button' onClick=location.href='index.php' value='Some data was empty, please fix it'></input><br><br>";
            }
ELSE {

//Count String Length
$CountNewPassword = strlen($NewPassword);

IF ($CountNewPassword < 5 OR $CountNewPassword > 10) {
echo "<font color=red>Password Must be at least 5 Characters, and no more than 10. </font><br><input type='button' onClick=location.href='index.php' value='Try Again / Change Your Account Password'></input><br><br>";
}
ELSE {

// Make sure New Password fields match
IF ( $NewPassword !== $ConfirmNew ) {
    echo "<font color=red>Confirm New Password Failed. <font color=white>New Password</font> and <font color=white>Confirm New Password</font> Fields Must Match. Please Try Again.</font><br><input type='button' onClick=location.href='index.php' value='Try Again / Change Your Account Password'></input><br><br>";
}
ELSE {

//Count Pin Length
$Pin = strlen($Pin);

IF ($Pin < 4 OR $Pin > 4) {
echo "<font color=red>Pin must have 4 digits.</font><br><input type='button' onClick=location.href='index.php' value='Try Again / Change Your Account Password'></input><br><br>";
}
ELSE {

//Encrypt Password and Username
$EncryptOldPassword = "0x" . md5($UserName . $OldPassword);
$EncryptNewPassword = "0x" . md5($UserName . $NewPassword);

$GetIP=$_SERVER['REMOTE_ADDR'];

$GetAccountInfo = Mysql_Query("SELECT * FROM users WHERE name = '$UserName'");
$GetAccountNum = Mysql_Num_Rows($GetAccountInfo);
IF ($GetAccountNum == 1) {
$GetAccountArray = Mysql_Fetch_Array($GetAccountInfo);
$GetPassword = $GetAccountArray['passwd'];
        $GetEmail = $GetAccountArray['email'];
$GetPin = $GetAccountArray['qq'];
$GetPassword = addslashes($GetPassword);
        $GetEmail = addslashes($GetEmail);
 $GetPin = addslashes($GetPin);
$rs = mysql_query("SELECT fn_varbintohexsubstring (1,'$GetPassword',1,0) AS result");
        $rs2 = mysql_query("SELECT '$GetEmail' AS result2");
$rs3 = mysql_query("SELECT '$GetPin' AS result3");
$GetResult = Mysql_Fetch_Array($rs);
        $GetResultEmail = Mysql_Fetch_Array($rs2);
$GetResultPin = Mysql_Fetch_Array($rs3);
$CheckPassword = $GetResult['result'];
        $CheckEmail = $GetResultEmail['result2'];
 $CheckPin = $GetResultPin['result3'];
        IF ($EMail == $CheckEmail) {
 IF ($Pin == $CheckPin) {
IF ($EncryptOldPassword == $CheckPassword) {
	Mysql_Query("CALL changePasswd ($GetAccountInfo->quoteSmart'$UserName', $EncryptNewPassword)");
	Mysql_Query("CALL changePasswd2 ($GetAccountInfo->quoteSmart'$UserName', $EncryptNewPassword)");
	echo "<font color='green' size='+2'>Password for Account: <font color=red>$UserName</font> has been changed</font><br><input type='button' onClick=location.href='index.php' value='Go Back'></input><br><br>";
}
ELSE {
	echo "<font color=red>Account Information is Incorrect! </font><br><input type='button' onClick=location.href='index.php' value='Try Again / Change Your Account Password'></input><br><br>";
}
}
}
ELSE {
echo "<font color=red>Account Information is Incorrect! </font><br><input type='button' onClick=location.href='index.php' value='Try Again / Change Your Account Password'></input><br><br>";
    }
   }
  }
}
}
}
?>

 

connector.php

<?php

    /*-------Config MySQL Database-------*/

    $DB_Host = "localhost";  // localhost or your IP for MySQL
    $DB_User = "root";  // Database username
    $DB_Password = "root";  // Database password
    $DB_Name = "data";  // Database name
    
    $ServerIP = "localhost";  // WAN IP (Public IP) or DOMAIN NAME of your Server
    $LanIP = "localhost";  // LAN IP of your Server
    $ServerPort = "29000";  // PW Server Port

$top=50;  // How many top players to show (on rank page)





    /*-------END User Config-------*/





    $db_link = mysql_connect($DB_Host, $DB_User, $DB_Password);
    $db = mysql_select_db("$DB_Name", $db_link);

    // security check for http_get variables to prevent injections
    foreach ($_GET as $key => $value)
    {
        $_GET[$key] = mysql_real_escape_string($value, $db_link);
    }
    // security check for http_get variables to prevent injections
    foreach ($_POST as $key => $value)
    {
        $_POST[$key] = mysql_real_escape_string($value, $db_link);
    }

?> 

Link to comment
Share on other sites

MySQL Database

 

/*
Navicat MySQL Data Transfer

Source Server         : localhost
Source Server Version : 50508
Source Host           : localhost:3306
Source Database       : data

Target Server Type    : MYSQL
Target Server Version : 50508
File Encoding         : 65001

Date: 2011-09-29 02:54:02
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `auth`
-- ----------------------------
DROP TABLE IF EXISTS `auth`;
CREATE TABLE `auth` (
  `userid` int(11) NOT NULL DEFAULT '0',
  `zoneid` int(11) NOT NULL DEFAULT '0',
  `rid` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`userid`,`zoneid`,`rid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of auth
-- ----------------------------

-- ----------------------------
-- Table structure for `forbid`
-- ----------------------------
DROP TABLE IF EXISTS `forbid`;
CREATE TABLE `forbid` (
  `userid` int(11) NOT NULL DEFAULT '0',
  `type` int(11) NOT NULL DEFAULT '0',
  `ctime` datetime NOT NULL,
  `forbid_time` int(11) NOT NULL DEFAULT '0',
  `reason` blob NOT NULL,
  `gmroleid` int(11) DEFAULT '0',
  PRIMARY KEY (`userid`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of forbid
-- ----------------------------

-- ----------------------------
-- Table structure for `iplimit`
-- ----------------------------
DROP TABLE IF EXISTS `iplimit`;
CREATE TABLE `iplimit` (
  `uid` int(11) NOT NULL DEFAULT '0',
  `ipaddr1` int(11) DEFAULT '0',
  `ipmask1` varchar(2) DEFAULT '',
  `ipaddr2` int(11) DEFAULT '0',
  `ipmask2` varchar(2) DEFAULT '',
  `ipaddr3` int(11) DEFAULT '0',
  `ipmask3` varchar(2) DEFAULT '',
  `enable` char(1) DEFAULT '',
  `lockstatus` char(1) DEFAULT '',
  PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of iplimit
-- ----------------------------

-- ----------------------------
-- Table structure for `point`
-- ----------------------------
DROP TABLE IF EXISTS `point`;
CREATE TABLE `point` (
  `uid` int(11) NOT NULL DEFAULT '0',
  `aid` int(11) NOT NULL DEFAULT '0',
  `time` int(11) NOT NULL DEFAULT '0',
  `zoneid` int(11) DEFAULT '0',
  `zonelocalid` int(11) DEFAULT '0',
  `accountstart` datetime DEFAULT NULL,
  `lastlogin` datetime DEFAULT NULL,
  `enddate` datetime DEFAULT NULL,
  PRIMARY KEY (`uid`,`aid`),
  KEY `IX_point_aidzoneid` (`aid`,`zoneid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of point
-- ----------------------------

-- ----------------------------
-- Table structure for `roles`
-- ----------------------------
DROP TABLE IF EXISTS `roles`;
CREATE TABLE `roles` (
  `account_id` int(11) NOT NULL,
  `role_id` int(11) NOT NULL,
  `role_name` varchar(32) NOT NULL,
  `role_level` smallint(6) NOT NULL,
  `role_race` tinyint(4) NOT NULL,
  `role_occupation` tinyint(4) NOT NULL,
  `role_gender` tinyint(4) NOT NULL,
  `role_spouse` int(11) NOT NULL,
  `faction_id` int(11) NOT NULL,
  `faction_name` varchar(32) NOT NULL,
  `faction_level` int(11) NOT NULL,
  `faction_domains` varchar(132) NOT NULL,
  `role_faction_rank` int(11) NOT NULL,
  `pvp_time` int(11) NOT NULL,
  `pvp_kills` int(11) NOT NULL,
  `pvp_deads` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of roles
-- ----------------------------

-- ----------------------------
-- Table structure for `usecashlog`
-- ----------------------------
DROP TABLE IF EXISTS `usecashlog`;
CREATE TABLE `usecashlog` (
  `userid` int(11) NOT NULL DEFAULT '0',
  `zoneid` int(11) NOT NULL DEFAULT '0',
  `sn` int(11) NOT NULL DEFAULT '0',
  `aid` int(11) NOT NULL DEFAULT '0',
  `point` int(11) NOT NULL DEFAULT '0',
  `cash` int(11) NOT NULL DEFAULT '0',
  `status` int(11) NOT NULL DEFAULT '0',
  `creatime` datetime NOT NULL,
  `fintime` datetime NOT NULL,
  KEY `IX_usecashlog_creatime` (`creatime`),
  KEY `IX_usecashlog_uzs` (`userid`,`zoneid`,`sn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of usecashlog
-- ----------------------------

-- ----------------------------
-- Table structure for `usecashnow`
-- ----------------------------
DROP TABLE IF EXISTS `usecashnow`;
CREATE TABLE `usecashnow` (
  `userid` int(11) NOT NULL DEFAULT '0',
  `zoneid` int(11) NOT NULL DEFAULT '0',
  `sn` int(11) NOT NULL DEFAULT '0',
  `aid` int(11) NOT NULL DEFAULT '0',
  `point` int(11) NOT NULL DEFAULT '0',
  `cash` int(11) NOT NULL DEFAULT '0',
  `status` int(11) NOT NULL DEFAULT '0',
  `creatime` datetime NOT NULL,
  PRIMARY KEY (`userid`,`zoneid`,`sn`),
  KEY `IX_usecashnow_creatime` (`creatime`),
  KEY `IX_usecashnow_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of usecashnow
-- ----------------------------

-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `ID` int(11) NOT NULL DEFAULT '0',
  `name` varchar(32) NOT NULL DEFAULT '',
  `passwd` varchar(64) NOT NULL,
  `Prompt` varchar(32) NOT NULL DEFAULT '',
  `answer` varchar(32) NOT NULL DEFAULT '',
  `truename` varchar(32) NOT NULL DEFAULT '',
  `idnumber` varchar(32) NOT NULL DEFAULT '',
  `email` varchar(64) NOT NULL DEFAULT '',
  `mobilenumber` varchar(32) DEFAULT '',
  `province` varchar(32) DEFAULT '',
  `city` varchar(32) DEFAULT '',
  `phonenumber` varchar(32) DEFAULT '',
  `address` varchar(64) DEFAULT '',
  `postalcode` varchar( DEFAULT '',
  `gender` int(11) DEFAULT '0',
  `birthday` datetime DEFAULT NULL,
  `creatime` datetime NOT NULL,
  `qq` varchar(32) DEFAULT '',
  `passwd2` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `IX_users_name` (`name`),
  KEY `IX_users_creatime` (`creatime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of users
-- ----------------------------

-- ----------------------------
-- Table structure for `uwebplayers`
-- ----------------------------
DROP TABLE IF EXISTS `uwebplayers`;
CREATE TABLE `uwebplayers` (
  `roleid` varchar(255) DEFAULT NULL,
  `rolename` varchar(255) DEFAULT NULL,
  `rolelevel` int(255) DEFAULT NULL,
  `rolestatus` varchar(255) DEFAULT NULL,
  `rolegender` varchar(255) DEFAULT NULL,
  `roleprof` varchar(255) DEFAULT NULL,
  `rolerep` int(255) DEFAULT NULL,
  `redname` int(255) DEFAULT NULL,
  `rednametime` int(255) DEFAULT NULL,
  `pinknametime` int(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of uwebplayers
-- ----------------------------

-- ----------------------------
-- Table structure for `world2`
-- ----------------------------
DROP TABLE IF EXISTS `world2`;
CREATE TABLE `world2` (
  `userid` int(11) DEFAULT NULL,
  `date` varchar(255) DEFAULT NULL,
  `hour` varchar(255) DEFAULT NULL,
  `minute` varchar(255) DEFAULT NULL,
  `msg` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of world2
-- ----------------------------

-- ----------------------------
-- Procedure structure for `acquireuserpasswd`
-- ----------------------------
DROP PROCEDURE IF EXISTS `acquireuserpasswd`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `acquireuserpasswd`(in name1 VARCHAR(64), out uid1 INTEGER, out passwd1 VARCHAR(64))
BEGIN
  DECLARE passwdtemp VARCHAR(64);
  START TRANSACTION;
    SELECT id, passwd INTO uid1, passwdtemp FROM users WHERE name = name1;
    SELECT fn_varbintohexsubstring(1,passwdtemp,1,0) INTO passwd1;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `addForbid`
-- ----------------------------
DROP PROCEDURE IF EXISTS `addForbid`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `addForbid`(in userid1 INTEGER, in type1 INTEGER, in forbid_time1 INTEGER, in reason1 BINARY(255), in gmroleid1 INTEGER)
BEGIN
DECLARE rowcount INTEGER;
  START TRANSACTION;
    UPDATE forbid SET ctime = now(), forbid_time = forbid_time1, reason = reason1, gmroleid = gmroleid1 WHERE userid = userid1 AND type = type1;
    SET rowcount = ROW_COUNT();
    IF rowcount = 0 THEN
      INSERT INTO forbid VALUES(userid1, type1, now(), forbid_time1, reason1, gmroleid);
    END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `addGM`
-- ----------------------------
DROP PROCEDURE IF EXISTS `addGM`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `addGM`(in userid INTEGER, in zoneid INTEGER)
BEGIN
  DECLARE x INTEGER;
  START TRANSACTION;
    SET x = 0;
    WHILE x < 12 DO
      INSERT INTO auth VALUES (userid, zoneid, x);
      SET x = x + 1;
    END WHILE;
    SET x = 100;
    WHILE x < 106 DO
      INSERT INTO auth VALUES (userid, zoneid, x);
      SET x = x + 1;
    END WHILE;
    SET x = 200;
    WHILE x < 215 DO
      INSERT INTO auth VALUES (userid, zoneid, x);
      SET x = x + 1;
    END WHILE;
    SET x = 500;
    WHILE x < 519 DO
      INSERT INTO auth VALUES (userid, zoneid, x);
      SET x = x + 1;
    END WHILE;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `adduser`
-- ----------------------------
DROP PROCEDURE IF EXISTS `adduser`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `adduser`(
  in name1 VARCHAR(64),
  in passwd1 VARCHAR(64),
  in prompt1 VARCHAR(32),
  in answer1 VARCHAR(32),
  in truename1 VARCHAR(32),
  in idnumber1 VARCHAR(32),
  in email1 VARCHAR(32),
  in mobilenumber1 VARCHAR(32),
  in province1 VARCHAR(32),
  in city1 VARCHAR(32),
  in phonenumber1 VARCHAR(32),
  in address1 VARCHAR(64),
  in postalcode1 VARCHAR(,
  in gender1 INTEGER,
  in birthday1 VARCHAR(32),
  in qq1 VARCHAR(32),
  in passwd21 VARCHAR(64)
)
BEGIN
  DECLARE idtemp INTEGER;
    SELECT IFNULL(MAX(id), 16) + 16 INTO idtemp FROM users;
    INSERT INTO users (id,name,passwd,prompt,answer,truename,idnumber,email,mobilenumber,province,city,phonenumber,address,postalcode,gender,birthday,creatime,qq,passwd2) VALUES( idtemp, name1, passwd1, prompt1, answer1, truename1, idnumber1, email1, mobilenumber1, province1, city1, phonenumber1, address1, postalcode1, gender1, birthday1, now(), qq1, passwd21 );
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `adduserpoint`
-- ----------------------------
DROP PROCEDURE IF EXISTS `adduserpoint`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `adduserpoint`(in uid1 INTEGER, in aid1 INTEGER, in time1 INTEGER)
BEGIN
DECLARE rowcount INTEGER;
START TRANSACTION;
    UPDATE point SET time = IFNULL(time,0) + time1 WHERE uid1 = uid AND aid1 = aid;
    SET rowcount = ROW_COUNT();
    IF rowcount = 0 THEN
      INSERT INTO point (uid,aid,time) VALUES (uid1,aid1,time1);
    END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `addUserPriv`
-- ----------------------------
DROP PROCEDURE IF EXISTS `addUserPriv`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `addUserPriv`(in userid INTEGER, in zoneid INTEGER, in rid INTEGER)
BEGIN
  START TRANSACTION;
    INSERT INTO auth VALUES(userid, zoneid, rid);
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `changePasswd`
-- ----------------------------
DROP PROCEDURE IF EXISTS `changePasswd`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `changePasswd`(in name1 VARCHAR(64), in passwd1 VARCHAR(64))
BEGIN
  START TRANSACTION;
    UPDATE users SET passwd = passwd1 WHERE name = name1;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `changePasswd2`
-- ----------------------------
DROP PROCEDURE IF EXISTS `changePasswd2`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `changePasswd2`(in name1 VARCHAR(64), in passwd21 VARCHAR(64))
BEGIN
  START TRANSACTION;
    UPDATE users SET passwd2 = passwd21 WHERE name = name1;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `clearonlinerecords`
-- ----------------------------
DROP PROCEDURE IF EXISTS `clearonlinerecords`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `clearonlinerecords`(in zoneid1 INTEGER, in aid1 INTEGER)
BEGIN
  START TRANSACTION;
    UPDATE point SET zoneid = NULL, zonelocalid = NULL WHERE aid = aid1 AND zoneid = zoneid1;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `deleteTimeoutForbid`
-- ----------------------------
DROP PROCEDURE IF EXISTS `deleteTimeoutForbid`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `deleteTimeoutForbid`(in userid1 INTEGER)
BEGIN
  START TRANSACTION;
    DELETE FROM forbid WHERE userid = userid1 AND timestampdiff(second, ctime, now()) > forbid_time;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `delUserPriv`
-- ----------------------------
DROP PROCEDURE IF EXISTS `delUserPriv`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `delUserPriv`(in userid1 INTEGER, in zoneid1 INTEGER, in rid1 INTEGER, in deltype1 INTEGER)
BEGIN
START TRANSACTION;
  IF deltype1 = 0 THEN
    DELETE FROM auth WHERE userid = userid1 AND zoneid = zoneid1 AND rid = rid1;
  ELSE
    IF deltype1 = 1 THEN
      DELETE FROM auth WHERE userid = userid1 AND zoneid = zoneid1;
    ELSE
      IF deltype1 = 2 THEN
        DELETE FROM auth WHERE userid = userid1;
      END IF;
    END IF;
  END IF;
COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `enableiplimit`
-- ----------------------------
DROP PROCEDURE IF EXISTS `enableiplimit`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `enableiplimit`(in uid1 INTEGER, in enable1 CHAR(1))
BEGIN
  DECLARE rowcount INTEGER;
  START TRANSACTION;
  UPDATE iplimit SET enable=enable1 WHERE uid=uid1;
  SET rowcount = ROW_COUNT();
  IF rowcount = 0 THEN
    INSERT INTO iplimit (uid,enable) VALUES (uid1,enable1);
  END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `lockuser`
-- ----------------------------
DROP PROCEDURE IF EXISTS `lockuser`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `lockuser`(in uid1 INTEGER, in lockstatus1 CHAR(1))
BEGIN
  DECLARE rowcount INTEGER;
  START TRANSACTION;
  UPDATE iplimit SET lockstatus=lockstatus1 WHERE uid=uid1;
  SET rowcount = ROW_COUNT();
  IF rowcount = 0 THEN
    INSERT INTO iplimit (uid,lockstatus,enable) VALUES (uid1,lockstatus1,'t');
  END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `recordoffline`
-- ----------------------------
DROP PROCEDURE IF EXISTS `recordoffline`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `recordoffline`(in uid1 INTEGER, in aid1 INTEGER, inout zoneid1 INTEGER, inout zonelocalid1 INTEGER, inout overwrite1 INTEGER)
BEGIN
  DECLARE rowcount INTEGER;
  START TRANSACTION;
    UPDATE point SET zoneid = NULL, zonelocalid = NULL WHERE uid = uid1 AND aid = aid1 AND zoneid = zoneid1;
    SET rowcount = ROW_COUNT();
    IF overwrite1 = rowcount THEN
      SELECT zoneid, zonelocalid INTO zoneid1, zonelocalid1 FROM point WHERE uid = uid1 AND aid = aid1;
    END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `recordonline`
-- ----------------------------
DROP PROCEDURE IF EXISTS `recordonline`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `recordonline`(in uid1 INTEGER, in aid1 INTEGER, inout zoneid1 INTEGER, inout zonelocalid1 INTEGER, inout overwrite INTEGER)
BEGIN
  DECLARE tmp_zoneid INTEGER;
  DECLARE tmp_zonelocalid INTEGER;
  DECLARE rowcount INTEGER;
  START TRANSACTION;
    SELECT SQL_CALC_FOUND_ROWS zoneid, zonelocalid INTO tmp_zoneid, tmp_zonelocalid FROM point WHERE uid = uid1 and aid = aid1;
    SET rowcount = FOUND_ROWS();
    IF rowcount = 0 THEN
      INSERT INTO point (uid, aid, time, zoneid, zonelocalid, lastlogin) VALUES (uid1, aid1, 0, zoneid1, zonelocalid1, now());
    ELSE IF tmp_zoneid IS NULL OR overwrite = 1 THEN
      UPDATE point SET zoneid = zoneid1, zonelocalid = zonelocalid1, lastlogin = now() WHERE uid = uid1 AND aid = aid1;
    END IF;
    END IF;
    IF tmp_zoneid IS NULL THEN
      SET overwrite = 1;
    ELSE
      SET zoneid1 = tmp_zoneid;
      SET zonelocalid1 = tmp_zonelocalid;
    END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `remaintime`
-- ----------------------------
DROP PROCEDURE IF EXISTS `remaintime`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `remaintime`(in uid1 INTEGER, in aid1 INTEGER, out remain INTEGER, out freetimeleft INTEGER)
BEGIN
  DECLARE enddate1 DATETIME;
  DECLARE now1 DATETIME;
  DECLARE rowcount INTEGER;
  START TRANSACTION;
  SET now1 = now();
  IF aid1 = 0 THEN
    SET remain = 86313600;
    SET enddate1 = date_add(now1, INTERVAL '30' DAY);
  ELSE
    SELECT time, IFNULL(enddate, now1) INTO remain, enddate1 FROM point WHERE uid = uid1 AND aid = aid1;
    SET rowcount = ROW_COUNT();
    IF rowcount = 0 THEN
      SET remain = 0;
      INSERT INTO point (uid,aid,time) VALUES (uid1, aid1, remain);
    END IF;
  END IF;
  SET freetimeleft = 0;
  IF enddate1 > now1 THEN
    SET freetimeleft = timestampdiff(second, now1, enddate1);
  END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `setiplimit`
-- ----------------------------
DROP PROCEDURE IF EXISTS `setiplimit`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `setiplimit`(in uid1 INTEGER, in ipaddr11 INTEGER, in ipmask11 VARCHAR(2), in ipaddr21 INTEGER, in ipmask21 VARCHAR(2), in ipaddr31 INTEGER, in ipmask31 VARCHAR(2), in enable1 CHAR(1))
BEGIN
  DECLARE rowcount INTEGER;
  START TRANSACTION;
    UPDATE iplimit SET ipaddr1 = ipaddr11, ipmask1 = ipmask11, ipaddr2 = ipaddr21, ipmask2 = ipmask21, ipaddr3 = ipaddr31, ipmask3 = ipmask31 WHERE uid = uid1;
    SET rowcount = ROW_COUNT();
    IF rowcount = 0 THEN
      INSERT INTO iplimit (uid, ipaddr1, ipmask1, ipaddr2, ipmask2, ipaddr3, ipmask3, enable1) VALUES (uid1, ipaddr11, ipmask11, ipaddr21, ipmask21, ipaddr31, ipmask31,'t');
    END IF;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `updateUserInfo`
-- ----------------------------
DROP PROCEDURE IF EXISTS `updateUserInfo`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `updateUserInfo`(
  in name1 VARCHAR(32),
  in prompt1 VARCHAR(32),
  in answer1 VARCHAR(32),
  in truename1 VARCHAR(32),
  in idnumber1 VARCHAR(32),
  in email1 VARCHAR(32),
  in mobilenumber1 VARCHAR(32),
  in province1 VARCHAR(32),
  in city1 VARCHAR(32),
  in phonenumber1 VARCHAR(32),
  in address1 VARCHAR(32),
  in postalcode1 VARCHAR(32),
  in gender1 INTEGER,
  in birthday1 VARCHAR(32),
  in qq1 VARCHAR(32)
)
BEGIN
  START TRANSACTION;
    UPDATE users SET prompt = prompt1, answer = answer1, truename = truename1, idnumber = idnumber1, email = email1, mobilenumber = mobilenumber1, province = province1, city = city1, phonenumber = phonenumber1, address = address1, postalcode = postalcode1, gender = gender1, birthday = birthda1, qq = qq1 WHERE name = name1;
  COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Procedure structure for `usecash`
-- ----------------------------
DROP PROCEDURE IF EXISTS `usecash`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `usecash`(
  in userid1 INTEGER,
  in zoneid1 INTEGER,
  in sn1 INTEGER,
  in aid1 INTEGER,
  in point1 INTEGER,
  in cash1 INTEGER,
  in status1 INTEGER,
  out error INTEGER
)
BEGIN
DECLARE sn_old INTEGER;
DECLARE aid_old INTEGER;
DECLARE point_old INTEGER;
DECLARE cash_old INTEGER;
DECLARE status_old INTEGER;
DECLARE createtime_old DATETIME;
DECLARE time_old INTEGER;
DECLARE need_restore INTEGER;
DECLARE exists1 INTEGER;
DECLARE rowcount INTEGER;
START TRANSACTION;
  SET error = 0;
  SET need_restore = 0;
  SELECT SQL_CALC_FOUND_ROWS sn, aid, point, cash, status, creatime INTO sn_old, aid_old, point_old, cash_old, status_old, createtime_old FROM usecashnow WHERE userid = userid1 AND zoneid = zoneid1 AND sn >= 0;
  SET rowcount = FOUND_ROWS();
  IF rowcount = 1 THEN
    SET exists1 = 1;
  ELSE
    SET exists1 = 0;
  END IF;
  IF status1 = 0 THEN
    IF exists1 = 0 THEN
      SELECT aid, point INTO aid1, point1 FROM usecashnow WHERE userid = userid1 AND zoneid = zoneid1 AND sn = sn1;
      SET point1 = IFNULL(point1,0);
      UPDATE point SET time = time-point1 WHERE uid = userid1 AND aid = aid1 AND time >= point1;
      SET rowcount = ROW_COUNT();
      IF rowcount = 1 THEN
        UPDATE usecashnow SET sn = 0, status = 1 WHERE userid = userid1 AND zoneid = zoneid1 AND sn = sn1;
      ELSE
        SET error = -8;
      END IF;
    END IF;
  ELSE
    IF status1 = 1 THEN
      IF exists1 = 0 THEN
        UPDATE point SET time = time-point1 WHERE uid = userid1 AND aid = aid1 AND time >= point1;
        SET rowcount = ROW_COUNT();
        IF rowcount = 1 THEN
          INSERT INTO usecashnow (userid, zoneid, sn, aid, point, cash, status, creatime) VALUES (userid1, zoneid1, sn1, aid1, point1, cash1, status1, now());
        ELSE
          INSERT INTO usecashnow SELECT userid1, zoneid1, IFNULL(min(sn),0)-1, aid1, point1, cash1, 0, now() FROM usecashnow WHERE userid = userid1 AND zoneid = zoneid1 AND 0 >= sn;
          SET error = -8;
        END IF;
      ELSE
        INSERT INTO usecashnow SELECT userid1, zoneid1, IFNULL(min(sn),0)-1, aid1, point1, cash1, 0, now() FROM usecashnow WHERE userid = userid1 AND zoneid = zoneid1 AND 0 >= sn;
        SET error = -7;
      END IF;
    ELSE
      IF status1 = 2 THEN
        IF exists1 = 1 AND status_old = 1 AND sn_old = 0 THEN
          UPDATE usecashnow SET sn = sn1, status = status1 WHERE userid = userid1 AND zoneid = zoneid1 AND sn = sn_old;
        ELSE
          SET error = -9;
        END IF;
      ELSE
        IF status1 = 3 THEN
           IF exists1 = 1 AND status_old = 2 THEN
            UPDATE usecashnow SET status = status1 WHERE userid = userid1 AND zoneid = zoneid1 AND sn = sn_old;
           ELSE
            SET error = -10;
            END IF;
        ELSE
         IF status1 = 4 THEN
          IF exists1 = 1 THEN
            DELETE FROM usecashnow WHERE userid = userid1 AND zoneid = zoneid1 AND sn = sn_old;
            INSERT INTO usecashlog (userid, zoneid, sn, aid, point, cash, status, creatime, fintime) VALUES (userid1, zoneid1, sn_old, aid_old, point_old, cash_old, status1, createtime_old, now());
          END IF;
          IF NOT (exists1 = 1 AND status_old = 3) THEN
            SET error = -11;
          END IF;
        ELSE
          SET error = -12;
        END IF;
      END IF;
    END IF;
  END IF;
  END IF;
  IF need_restore = 1 THEN
    UPDATE point SET time = time+point_old WHERE uid = userid1 AND aid = aid_old;
    DELETE FROM usecashnow WHERE userid = userid1 AND zoneid = zoneid1 AND sn = sn_old;
    INSERT INTO usecashlog (userid, zoneid, sn, aid, point, cash, status, creatime, fintime) VALUES (userid1, zoneid1, sn_old, aid_old, point_old, cash_old, status1, createtime_old, now());
  END IF;
COMMIT;
END
;;
DELIMITER ;

-- ----------------------------
-- Function structure for `fn_varbintohexsubstring`
-- ----------------------------
DROP FUNCTION IF EXISTS `fn_varbintohexsubstring`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `fn_varbintohexsubstring`(fsetprefix bit,pbinin varbinary(8000),startoffset int,cbytesin int) RETURNS varchar(4000) CHARSET latin1
    READS SQL DATA
BEGIN
  DECLARE pstrout VARCHAR(4000);
  DECLARE i int;
  DECLARE firstnibble int;
  DECLARE secondnibble int;
  DECLARE tempint int;
  DECLARE hexstring char( 16);
  BEGIN
    IF( pbinin IS NOT NULL) THEN
      SET i= 0, cbytesin= CASE WHEN( cbytesin> 0) THEN cbytesin ELSE LENGTH( pbinin) END,
         pstrout= CASE WHEN( fsetprefix= 1) THEN '0x'  ELSE ''  END,
         hexstring= '0123456789abcdef';
      IF((( cbytesin * 2) + 2> 4000) or( startoffset< 1)) THEN
        RETURN NULL;
      END IF;
      WHILE( i< cbytesin) DO
        SET tempint= ASCII( substring( pbinin, i + startoffset, 1));
        SET firstnibble= TRUNCATE((tempint / 16),0);
        SET secondnibble= tempint % 16;
        SET pstrout= CONCAT(pstrout ,cast( substring( hexstring,( firstnibble+1), 1) AS CHAR), cast( substring( hexstring,( secondnibble+1), 1) AS CHAR));
        SET i= i + 1;
      END WHILE;
      RETURN pstrout;
    END IF;
    RETURN NULL;
  END;
END
;;
DELIMITER ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.