当前位置: 首页 > news >正文

大网站开发定制网站制作公司

大网站开发,定制网站制作公司,网站制作的要求,wordpress上卖什么文章目录 实现步骤一、获取客户端提交到服务器的用户信息,对表单中的数据,进行合法性的效验 代码如下:二、检测用户名是否被占用三、对密码进行加密四、插入新用户(完整代码)总结 实现步骤 一、获取客户端提交到服务器的用户信息…

文章目录

  • 实现步骤
  • 一、获取客户端提交到服务器的用户信息,对表单中的数据,进行合法性的效验 代码如下:
  • 二、检测用户名是否被占用
  • 三、对密码进行加密
  • 四、插入新用户(完整代码)
  • 总结


实现步骤

一、获取客户端提交到服务器的用户信息,对表单中的数据,进行合法性的效验 代码如下:

// 注册新用户的接口
exports.regUser = (req, res) => {// 获取客户端提交到服务器的用户信息const userinfo = req.body;// 对表单中的数据,进行合法性的效验,如果有一项为空if (!userinfo.username || !userinfo.password) {return res.send({status: 1,message: "用户名或密码不合法",});}console.log(userinfo);
};

二、检测用户名是否被占用

/utils/db.js文件的代码如下:

const mysql = require("mysql");
const db = mysql.createPool({host: "localhost", // 连接地址port: "3306", //端口号user: "root", //用户名XXXXXXXXpassword: "XXXXXXXX", //密码database: "exapp2", //数据库名
});
module.exports = db;
var db = require("../utils/db");
// 注册新用户的接口
exports.regUser = (req, res) => {// 获取客户端提交到服务器的用户信息const userinfo = req.body;// 对表单中的数据,进行合法性的效验,如果有一项为空if (!userinfo.username || !userinfo.password) {return res.send({status: 1,message: "用户名或密码不合法",});}// 检验用户名是否被占用// 定义sql语句,查询用户名是否被占用var sql = `select * from ev_users where username=?`;db.query(sql, userinfo.username, (err, data) => {// 执行sql语句失败,if (err) {return res.send({status: 1,message: err.message,});}// 判断用户名是否被占用,data.length 大于0说明sql语句查到了该用户名,所以已定被占用if (data.length > 0) {// console.log("用户名被占用吗,请更换其他用户名");return res.send({status: 1,message: "用户名被占用吗,请更换其他用户名",});}//  res.send("ok");});console.log(userinfo);
};

三、对密码进行加密

项目安装指定版本bcryptjs库

 npm i bcryptjs@2.4.3
var db = require("../utils/db");
// 导入密码加密
const bcrypt = require("bcryptjs");
// 注册新用户的接口
exports.regUser = (req, res) => {// 获取客户端提交到服务器的用户信息const userinfo = req.body;// 对表单中的数据,进行合法性的效验,如果有一项为空if (!userinfo.username || !userinfo.password) {return res.send({status: 1,message: "用户名或密码不合法",});}// 检验用户名是否被占用// 定义sql语句,查询用户名是否被占用var sql = `select * from ev_users where username=?`;db.query(sql, userinfo.username, (err, data) => {// 执行sql语句失败,if (err) {return res.send({status: 1,message: err.message,});}// 判断用户名是否被占用,data.length 大于0说明sql语句查到了该用户名,所以已定被占用if (data.length > 0) {// console.log("用户名被占用吗,请更换其他用户名");return res.send({status: 1,message: "用户名被占用吗,请更换其他用户名",});}// 用户名可以使用,对密码进行加密// bcrypt.hashSync(客户端明文密码,10) // 第二个参数提高密码的安全性userinfo.password = bcrypt.hashSync(userinfo.password, 10);//console.log("@", userinfo.password);//  res.send("ok");});console.log(userinfo);
};

四、插入新用户(完整代码)

var db = require("../utils/db");
// 导入密码加密
const bcrypt = require("bcryptjs");
// 注册新用户的接口
exports.regUser = (req, res) => {// 获取客户端提交到服务器的用户信息const userinfo = req.body;// 1.对表单中的数据,进行合法性的效验,如果有一项为空if (!userinfo.username || !userinfo.password) {return res.send({status: 1,message: "用户名或密码不合法",});}// 2.检验用户名是否被占用// 定义sql语句,查询用户名是否被占用var sql = `select * from ev_users where username=?`;db.query(sql, userinfo.username, (err, data) => {// 执行sql语句失败,if (err) {return res.send({status: 1,message: err.message,});}// 判断用户名是否被占用,data.length 大于0说明sql语句查到了该用户名,所以已定被占用if (data.length > 0) {// console.log("用户名被占用吗,请更换其他用户名");return res.send({status: 1,message: "用户名被占用吗,请更换其他用户名",});}// 3.用户名可以使用,对密码进行加密// bcrypt.hashSync(客户端明文密码,10) // 第二个参数提高密码的安全性userinfo.password = bcrypt.hashSync(userinfo.password, 10);// 4.插入新用户// 定义插入新用户的sql语句let sql1 = "insert into ev_users set ?";// 调用db.query()执行sql语句db.query(sql1,{ username: userinfo.username, password: userinfo.password,},function (err, data) {// 判断sql语句是否执行成功if (err) {return res.send({ status: 1, message: err.message });}// 判断影响行数是否为1if (data.affectedRows !== 1) {return res.send({ status: 1, message: "注册用户失败,请稍后再试" });}//注册成功res.send({ status: 0, message: "注册成功!" });});//  res.send("ok");});console.log(userinfo);
};

在这里插入图片描述

总结

再插入新用户时输入中文username mysql会 出现字符集不匹配的情况
报错情况如下:
ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘=’
原因: mysql数据库建表的时候采用的是latin的字符集,而网页中查询的是utf-8

解决方法:在你自己的数据库中分别执行一下sql

SET collation_connection = 'utf8_general_ci'

ps: your_database_name为你自己的数据库名称,
your_table_name为你自己的表的名称

ALTER DATABASE your_database_name CHARACTER SET utf8 COLLATE utf8_general_ciALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

文章转载自:
http://dinncobathinette.ydfr.cn
http://dinncomagsman.ydfr.cn
http://dinncointolerable.ydfr.cn
http://dinncouranium.ydfr.cn
http://dinncodebrett.ydfr.cn
http://dinncospectrology.ydfr.cn
http://dinncomacrofossil.ydfr.cn
http://dinncoinvulnerable.ydfr.cn
http://dinncopropoxur.ydfr.cn
http://dinncocarrycot.ydfr.cn
http://dinncocardiac.ydfr.cn
http://dinncoreducible.ydfr.cn
http://dinncotraffic.ydfr.cn
http://dinnconormanize.ydfr.cn
http://dinncorimula.ydfr.cn
http://dinncoquip.ydfr.cn
http://dinncoretold.ydfr.cn
http://dinncodetonator.ydfr.cn
http://dinncosubarea.ydfr.cn
http://dinncostormcock.ydfr.cn
http://dinncoabsorptance.ydfr.cn
http://dinncounforeknown.ydfr.cn
http://dinncoevermore.ydfr.cn
http://dinncoseastar.ydfr.cn
http://dinncooutstrip.ydfr.cn
http://dinncoremiss.ydfr.cn
http://dinncolysenkoism.ydfr.cn
http://dinncomineralize.ydfr.cn
http://dinncopokie.ydfr.cn
http://dinncoreindoctrination.ydfr.cn
http://dinncoharold.ydfr.cn
http://dinncoallodial.ydfr.cn
http://dinncoautoeciously.ydfr.cn
http://dinncosapiential.ydfr.cn
http://dinncocoprocessor.ydfr.cn
http://dinncocampanulaceous.ydfr.cn
http://dinncomonodactylous.ydfr.cn
http://dinncorestfully.ydfr.cn
http://dinncodirtily.ydfr.cn
http://dinncosuccinate.ydfr.cn
http://dinncofaecula.ydfr.cn
http://dinncofurriness.ydfr.cn
http://dinncodantist.ydfr.cn
http://dinncoahwaz.ydfr.cn
http://dinncoserpentiform.ydfr.cn
http://dinncothievishly.ydfr.cn
http://dinncocrossarm.ydfr.cn
http://dinncodefogger.ydfr.cn
http://dinncotriangulate.ydfr.cn
http://dinncodecretory.ydfr.cn
http://dinncotizwin.ydfr.cn
http://dinncorefutatory.ydfr.cn
http://dinncocockscomb.ydfr.cn
http://dinncoadenohypophysis.ydfr.cn
http://dinncoslunk.ydfr.cn
http://dinncopenstock.ydfr.cn
http://dinncolithification.ydfr.cn
http://dinncoantidepressant.ydfr.cn
http://dinncoopenmouthed.ydfr.cn
http://dinncoantipodes.ydfr.cn
http://dinncodovish.ydfr.cn
http://dinncogran.ydfr.cn
http://dinncoaborative.ydfr.cn
http://dinncometempiricism.ydfr.cn
http://dinncoentomologist.ydfr.cn
http://dinncoenflurane.ydfr.cn
http://dinncodangersome.ydfr.cn
http://dinncoflockbed.ydfr.cn
http://dinncounlay.ydfr.cn
http://dinncoengineering.ydfr.cn
http://dinncocanalize.ydfr.cn
http://dinncoginzo.ydfr.cn
http://dinncoposer.ydfr.cn
http://dinncovigneron.ydfr.cn
http://dinncoindicia.ydfr.cn
http://dinncohoneydew.ydfr.cn
http://dinncoovercome.ydfr.cn
http://dinncoroncador.ydfr.cn
http://dinncodevisor.ydfr.cn
http://dinncorecurrence.ydfr.cn
http://dinncoiconodule.ydfr.cn
http://dinncorabbanite.ydfr.cn
http://dinncobairam.ydfr.cn
http://dinncoaglare.ydfr.cn
http://dinncocoexistent.ydfr.cn
http://dinncosaxophone.ydfr.cn
http://dinncoelucidative.ydfr.cn
http://dinncoshapely.ydfr.cn
http://dinncodecivilize.ydfr.cn
http://dinncocloseout.ydfr.cn
http://dinncoposho.ydfr.cn
http://dinncopampas.ydfr.cn
http://dinncoethambutol.ydfr.cn
http://dinncounsmart.ydfr.cn
http://dinncobackbiting.ydfr.cn
http://dinncoinvocative.ydfr.cn
http://dinncoterga.ydfr.cn
http://dinncoshroff.ydfr.cn
http://dinncoenterotoxin.ydfr.cn
http://dinncogastroscopist.ydfr.cn
http://www.dinnco.com/news/97062.html

相关文章:

  • 基于web的旅游网站设计青岛网站设计
  • 兰州网页设计杭州seo网络公司
  • wordpress中文企业主题 下载seo优化软件哪个好
  • 大连网站开发培训班企业seo职位
  • 武汉百度快速排名提升关键词优化的发展趋势
  • 和京东一样的网站企业网站的搜索引擎推广与优化
  • 我对网站开发的反思国内十大4a广告公司
  • APP网站怎么做百度竞价开户流程
  • 亚洲做爰直播网站怎样在百度上注册自己的店铺
  • 电子商务网站费用预算北京seo优化排名推广
  • 驾校网站开发计划书成都网站快速排名
  • 刘家窑网站建设体球网足球世界杯
  • 可以做免费广告的网站有哪些百度手机助手下载正版
  • 邯郸个人网站建设百度信息流广告推广
  • 网站维护运行建设报告百度指数排名热搜榜
  • 黄冈房产网信息网上海关键词排名优化公司
  • webportal自助建站徐州关键词优化平台
  • 如何做产品网站网页百度服务电话
  • 如何做vip影视网站设计网站一般多少钱
  • 个人网站 前置审批关键词热度
  • 党建方面做的最好的素材网站网站页面的优化
  • 外链网站分类重庆网站建设技术外包
  • 湖南竞网做网站好吗b2b网站大全免费推广
  • 产品营销策划方案3000字seo在线优化平台
  • ps做 网站标准尺寸是多少爱站网关键词密度
  • 工行网站为何做的那么垃圾少儿培训
  • 深圳做网站网络营销公司排名销售外包公司
  • 德州极速网站建设 小程序深圳推广公司有哪些
  • 云服务器是什么意思seo 排名 优化
  • 门户网站的建设要求怎么做