function regenPass($sid) { $newPass = rand_pass(8); if (mysql_query("UPDATE `users` SET `password` = '{$newPass}' WHERE `user_id` = {$sid}")) { return true; } else { return false; } }
function add_user($sid, $lname, $fname, $department) { $sid = mysql_real_escape_string($sid); $lname = ucwords(strtolower(mysql_real_escape_string($lname))); $fname = ucwords(strtolower(mysql_real_escape_string($fname))); $pass = rand_pass(8); $sql = "INSERT INTO\n\t\t\t\t`users`\n\t\t\t(\n\t\t\t\t`user_group`,\n\t\t\t\t`student_id`,\n\t\t\t\t`password`,\n\t\t\t\t`lname`,\n\t\t\t\t`fname`,\n\t\t\t\t`department`\n\t\t\t)\n\t\t\tVALUES\n\t\t\t(\n\t\t\t\t'user',\n\t\t\t\t'{$sid}',\n\t\t\t\t'{$pass}',\n\t\t\t\t'{$lname}',\n\t\t\t\t'{$fname}',\n\t\t\t\t'{$department}'\n\t\t\t)"; if (mysql_query($sql)) { return true; } else { return mysql_error(); } }
function theme_reg_form() { ?> <form role="form" method="post"> <div class="form-group"> <label class="control-label"><i class="fa fa-star fa-lg"> Roll Number</i></label> <input class="form-control" name="roll" placeholder="Enter your roll number" /> </div> <div class="form-group"> <label class="control-label"><i class="fa fa-user fa-lg"> Name</i></label> <input class="form-control" name="name" placeholder="Enter your name" /> </div> <div class="form-group"> <label class="control-label"><i class="fa fa-key fa-lg"> Password</i></label> <input class="form-control" name="password" placeholder="Enter a password" value="<? echo rand_pass(); ?>" /> </div> <div class="form-group"> <button class="btn btn-danger" type="submit">Register</button> </div> </form> <? }
function validate_input($valid, &$p, &$error) { $error = null; if ($valid['type'] != 'func') { if (is_array($p)) { $val =& $p[$valid['_input']]; } else { $val =& $p; } } switch ($valid['type']) { case 'address': $val = string_check($val); if (empty($valid['blank']) and strlen($val) < 4) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid address.'; } if (!empty($valid['lines']) and !empty($val) and substr_count($val, "\n") < $valid['lines'] - 1) { $error = 'This address must contain at least ' . $valid['lines'] . ' lines.'; } if (!empty($valid['format'])) { $val = str_replace(array("\r", "\n", "\r\n", ', '), ',', $val); } break; case 'array': case 'choice': case 'select': // $val can't be an array at this point as that's sorted higher up by validate_input_array() if (!is_array($valid['options']) and function_exists($valid['options'])) { $valid['options'] = $valid['options'](); } if (is_array($valid['options'])) { if (is_assoc($valid['options'])) { $err = !@isset($valid['options'][$val]); } else { $err = !in_array($val, $valid['options']); } } elseif (isset($valid['no-opts'])) { $val = ''; } else { $err = true; $valid['msg'] = 'The options could not be found for this field.'; } if (isset($valid['not-empty']) and empty($val)) { $err = true; } if (!empty($err)) { if (!empty($valid['blank'])) { $val = ''; } elseif (!empty($valid['msg'])) { $error = $valid['msg']; } else { $error = 'You must select one of the available options.'; } } break; case 'bool': case 'boolean': if (!empty($val)) { $val = !empty($valid['set']) ? $valid['set'] : 1; } elseif (!empty($valid['mandatory'])) { $error = 'You must tick this box to continue.'; } else { $val = !empty($valid['empty']) ? $valid['empty'] : 0; } break; case 'clear': $val = false; break; // we can't do this because of the isset check in valid; use the func method to point to valid_copy instead // case 'copy': // $val=$p[$valid['copy']]; // break; // we can't do this because of the isset check in valid; use the func method to point to valid_copy instead // case 'copy': // $val=$p[$valid['copy']]; // break; case 'currency': if (!make_currency($val, $valid['blank'] ? 1 : false)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid currency value'; } if (!empty($valid['positive']) and $val < 0) { $val *= -1; } break; case 'dat': case 'date': // we had to be careful here, as when we moved to a function with &$error // it started adding the error even if we planned to ignore it // use $err in these cases but might be better to pass on the blank flag // to sub functions of the validator $func = 'sql_' . $valid['type']; $val = $func($val, $err); $today_date = date('Y-m-d'); if (empty($val)) { if (!empty($valid['blank'])) { $val = $valid['blank'] == 'today' ? $today_date : ''; } else { $error = !empty($err) ? $err : 'The date you entered was not recognised'; } } else { if (!empty($valid['past'])) { $valid['max'] = $today_date; } if (!empty($valid['future'])) { $valid['min'] = $today_date; } if (!empty($valid['max']) and $val > $valid['max']) { $error = 'The date specified is greater than the maximum allowed.'; } if (!empty($valid['min']) and $val < $valid['min']) { $error = 'The date specified is less than the minimum allowed.'; } } break; case 'dob': if (!empty($val)) { $val = date_from_dob($val); } if (empty($val) and empty($valid['blank'])) { if (!empty($valid['msg'])) { $error = $valid['msg']; } else { $error = 'You must enter a valid date of birth, try ' . (defined(DATE_USA) ? 'mm/dd/yy' : 'dd/mm/yy') . '.'; } } if (isset($valid['max']) or isset($valid['min'])) { $age = age_from_dob($val); if (!empty($valid['max']) and $age > $valid['max']) { $error = 'This date of birth indicates an age of ' . $age . '. It is required that the age is ' . $valid['max'] . ' or less.'; } if (!empty($valid['min']) and $age < $valid['min']) { $error = 'This date of birth indicates an age of ' . $age . '. It is required that the age is ' . $valid['min'] . ' or more.'; } } if ($val > date('Y-m-d')) { $error = 'A date of birth may not be in the future. If time travel has been invented, please let us know last year.'; } break; case 'email': if (!make_email($val, $valid['blank'] ? 1 : false)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid email address.'; } break; case 'equal': if (!string_compare($val, $valid['equal'])) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter the exact value.'; } break; // this isn't really a data type, could be removed now that we can accept arrays // this isn't really a data type, could be removed now that we can accept arrays case 'extra': $extra = array(); if (is_array($val['key'])) { foreach ($val['key'] as $n => $key) { $extra[string_check($key)] = string_check($val['val'][$n]); } } $val = serialize($extra); break; case 'html': $val = make_html($val, $valid['tags'], !empty($valid['multi_byte']) ? true : false); if ($valid['length'] > 0) { if (strlen($val) < $valid['length']) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a value at least ' . ($valid['length'] == 1 ? '1 character' : $valid['length'] . ' characters.') . ' long'; } } break; case 'image': break; case 'keygen': if (empty($val) and empty($valid['regen'])) { $val = rand_pass(); } break; case 'name': $val = make_name($val); if (empty($valid['blank']) and empty($val)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid name.'; } break; case 'num': case 'number': if (!is_number($val, $valid['blank'] ? 1 : false)) { if (!empty($valid['default'])) { $val = $valid['default']; } else { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid number.'; } } if (!empty($val)) { // for legacy support if (isset($valid['ulimit'])) { $valid['max'] = $valid['ulimit']; } if (isset($valid['dlimit'])) { $valid['min'] = $valid['dlimit']; } // if (isset($valid['max']) and $val > $valid['max']) { $error = 'You must enter a number no greater than ' . $valid['max'] . '.'; } if (isset($valid['min']) and $val < $valid['min']) { $error = 'You must enter a number no lower than ' . $valid['min'] . '.'; } if (isset($valid['max-other']) and $val > $p[$valid['max-other']]) { $error = 'You must enter a number no greater than ' . $p[$valid['max-other']] . '.'; } } break; case 'phone': if (isset($valid['other'])) { $error = !make_phones($val, $p[$valid['other']]); } else { $error = !make_phone($val, $valid['blank'] ? 1 : false); } if (!empty($error)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid phone number.'; } break; case 'postcode': if (!make_postcode($val, $valid['blank'] ? 1 : false)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid postcode.'; } break; case 'time': if (!make_time($val, $valid['blank'] ? 1 : false, $valid['format'] ? $valid['format'] : null)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid time.'; } break; case 'url': case 'website': if (!make_website($val, $valid['blank'] ? 1 : false)) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a valid website address.'; } if (is_array($valid['unique'])) { $check = query("SELECT " . $valid['unique']['id'] . " FROM " . $valid['unique']['table'] . " WHERE website='{$val}'", 'single'); if ($check > 0) { $error = 'The website address you entered is already registered.'; } } break; case 'func': $func = $valid['func']; if (function_exists($func)) { if (!$func($p, $err, $valid)) { $error = !empty($valid['msg']) ? $valid['msg'] : $err; } break; } default: if (!empty($val)) { $val = string_check($val, $valid['strip']); } if (!empty($valid['length'])) { if (strlen($val) < $valid['length']) { $error = !empty($valid['msg']) ? $valid['msg'] : 'You must enter a value at least ' . ($valid['length'] == 1 ? '1 character' : $valid['length'] . ' characters.') . ' long'; } } elseif (!empty($valid['default']) and empty($val)) { $val = $valid['default']; } if (!empty($valid['max']) and $strlen > $valid['max']) { $error = 'You may not enter a value longer than ' . $valid['max'] . ' characters.'; } } validate_unique($valid, $val, $error); if ($error) { return false; } return true; }
function make_pass_rand(&$p, $names = null) { $p[!empty($names['input']) ? $names['input'] : 'pass'] = rand_pass(); make_pass($p, $names); }
/** * 发送验证码 * * @param $mobile * @return bool */ function send_verify($mobile) { if (isset($_SESSION['mobile_verify'])) { $this->error = array('msg' => '太快的请求发送验证码'); } else { $this->ci->session->mark_as_temp('mobile_verify', 60); $this->ci->load->helper('sms'); //加载短信发送方法 $this->ci->load->helper('verify'); $verify_code = rand_pass(); $flag = send_sms($mobile, $verify_code, 'register', true); //最后一个参数测试时改为true或者去掉 if ($flag) { $_SESSION['sms_verify'] = array('mobile' => $mobile, 'verify' => md5($verify_code)); return $verify_code; } else { unset($_SESSION['mobile_verify']); $this->error = array('msg' => '发送短信失败'); } } return FALSE; }
public static function relance(PlUser $user, $nbx = -1) { global $globals; if ($nbx < 0) { $nbx = $globals->core->NbIns; } $res = XDB::fetchOneCell('SELECT r.date, r.email, r.bestalias FROM register_pending WHERE r.hash = \'INSCRIT\' AND uid = {?}', $user->id()); if (!$res) { return false; } else { list($date, $email, $alias) = $res; } $hash = rand_url_id(12); $pass = rand_pass(); $pass_encrypted = sha1($pass); $fdate = strftime('%d %B %Y', strtotime($date)); $mymail = new PlMailer('marketing/relance.mail.tpl'); $mymail->assign('nbdix', $nbx); $mymail->assign('fdate', $fdate); $mymail->assign('lusername', $alias); $mymail->assign('nveau_pass', $pass); $mymail->assign('baseurl', $globals->baseurl); $mymail->assign('lins_id', $hash); $mymail->assign('lemail', $email); $mymail->assign('subj', ucfirst($globals->mail->domain) . ' : ' . $alias); $mymail->send(); XDB::execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_encrypted, $user->id()); return $user->fullName(); }
function create_user($data, $password) { $user = $this->ci->users->get_user_by_wechat($data['openid']); if ($user) { //用户存在的话 更新数据 $flag = $this->update_user($data, $user); return $flag; } else { $this->ci->load->helper('verify'); $username = $data['nickname'] . rand_pass(4); if (!$this->ci->users->is_username_available($username)) { $this->create_user($data, $password); } $hasher = new PasswordHash($this->ci->config->item('phpass_hash_strength', 'tank_auth'), $this->ci->config->item('phpass_hash_portable', 'tank_auth')); $hashed_password = $hasher->HashPassword($password); $gender = -1; switch ($data['sex']) { case '1': $gender = 1; break; case '2': $gender = 0; break; default: $gender = -1; } $user = array('username' => $username, 'password' => $hashed_password, 'wechat_id' => $data['openid'], 'wechat_avatar' => $data['headimgurl'], 'wechat_refresh_token' => $data['refresh_token'], 'wechat_auth_time' => date("Y-m-d H:i:s", time()), 'nickname' => $data['nickname'], 'gender' => $gender, 'address' => $data['province'] . $data['city'], 'last_ip' => $this->ci->input->ip_address(), 'from' => 'wechat', 'wechat_auth_num' => 1); if (!is_null($res = $this->ci->users->create_user($user))) { $this->create_autologin($res['user_id']); $data['user_id'] = $res['user_id']; $data['password'] = $password; return $data; } } return NULL; }