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

贵阳网站制作服务商百度账号怎么改用户名

贵阳网站制作服务商,百度账号怎么改用户名,用于手机的导航网站要怎么做,北京微信网站建设电话咨询什么是会话技术? Cookie 以登录为例,用户在浏览器中将账号密码输入并勾选自动登录,浏览器发送请求,请求头中设置Cookie:userName:张三 ,password:1234aa ,若登录成功,服务器将这个cookie保存…

什么是会话技术? 

Cookie

以登录为例,用户在浏览器中将账号密码输入并勾选自动登录,浏览器发送请求,请求头中设置Cookie:userName:'张三' ,password:'1234aa'  ,若登录成功,服务器将这个cookie保存下来,后续用户登录,服务器向客户端(即浏览器)发送之前存储的用户cookie自动登录。

 Session

底层还是用cookie,每个浏览器对应一个session,用户通过浏览器发送请求,请求头中携带sessionId来区分要访问哪个session

 令牌技术jwt

令牌格式 

前面两部分是基于Base64编码的,最后一部分是基于编码算法(这里是HS256)和密钥的 

 使用流程

以自动登录为例,用户输入账号密码后请求服务器进行登录,服务器查询数据库校验账号密码成功后生成令牌(token),并把token发给用户,浏览器要将这个令牌记录下来,后续发送请求时携带这个令牌。

后端人员需要做的事👇

编写生成token的方法,在请求响应成功后将token响应给服务端

1.导入依赖

<!--    token--><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.1</version></dependency><!--        基于java,需要引入这个--><dependency><groupId>com.auth0</groupId><artifactId>java-jwt</artifactId><version>3.4.0</version></dependency>

2.写一个JwtUtil

public class JwtUtil {private static final String secretKey="odpodpodp";//密钥  注意这个密钥不能太短private static final int  expireTime=3600*1000;//有效期为1小时   (单位:毫秒)//生成tokenpublic static String buildToken(int userId,String password){HashMap<String, Object> map = new HashMap<>();map.put("userId",userId);map.put("password",password);String token=Jwts.builder().addClaims(map)//载荷(payload  即要加密的json字符串)   不是setClaims!!.signWith(SignatureAlgorithm.HS256,secretKey)//指定加密算法和密钥.setExpiration(new Date(currentTimeMillis()+expireTime))//设置有效期为1h.compact();//生成return token;}//jwt校验public static Claims parseJwt(String token){Claims claims = (Claims) Jwts.parser().setSigningKey(secretKey)//指定密钥.parse(token).getBody();//生成json格式的mapreturn claims;}}

前端人员需要做的事👇

浏览器可以把服务器响应的token以键值对的形式存储在localStorage中

后续发送请求时携带token到后端去解析

测试一下

控制器

@RestController
//登录注册模块控制器
@RequestMapping("login")
public class LoginController {@PostMapping("/testToken")public Result testToken(@RequestBody User user){int userId = user.getUserId();String password = user.getPassword();if(true)//校验账号密码的逻辑{String token = JwtUtil.buildToken(userId, password);System.out.println("token:"+token);//测试一下解码tokenSystem.out.println("解码token...");System.out.println(JwtUtil.parseJwt(token));return new Result(Code.RETURN_TOKEN_OK,"登录成功,返回token",token);}return new Result(Code.RETURN_TOKEN_FAIL,"登录失败,请验证账号密码",null);}
}

用postman访问接口

控制台输出

exp是还有多久过期


文章转载自:
http://dinncoslacken.tqpr.cn
http://dinncolivestock.tqpr.cn
http://dinncoshrinkingly.tqpr.cn
http://dinncoszechwan.tqpr.cn
http://dinncodaggerboard.tqpr.cn
http://dinncoreb.tqpr.cn
http://dinncotremissis.tqpr.cn
http://dinncoexcarnate.tqpr.cn
http://dinncotrechometer.tqpr.cn
http://dinncoamaldar.tqpr.cn
http://dinncoharshly.tqpr.cn
http://dinncoveda.tqpr.cn
http://dinncoflyness.tqpr.cn
http://dinncoserai.tqpr.cn
http://dinncohandwringer.tqpr.cn
http://dinncovop.tqpr.cn
http://dinncoandromonoecism.tqpr.cn
http://dinncolegong.tqpr.cn
http://dinncoparagrapher.tqpr.cn
http://dinnconigerian.tqpr.cn
http://dinncobipedal.tqpr.cn
http://dinncolilliputian.tqpr.cn
http://dinncodisallowable.tqpr.cn
http://dinncodisembroil.tqpr.cn
http://dinncoconsummately.tqpr.cn
http://dinncohearthrug.tqpr.cn
http://dinncokidskin.tqpr.cn
http://dinncobemazed.tqpr.cn
http://dinncosuccorance.tqpr.cn
http://dinncobiface.tqpr.cn
http://dinncobreakpoint.tqpr.cn
http://dinncohumanly.tqpr.cn
http://dinncougric.tqpr.cn
http://dinncochaeta.tqpr.cn
http://dinncomilldam.tqpr.cn
http://dinncobarefaced.tqpr.cn
http://dinncobasion.tqpr.cn
http://dinncofad.tqpr.cn
http://dinncohobodom.tqpr.cn
http://dinncoaerophysics.tqpr.cn
http://dinncodalles.tqpr.cn
http://dinncoternate.tqpr.cn
http://dinncoparturifacient.tqpr.cn
http://dinncoopportunity.tqpr.cn
http://dinncohypoacusis.tqpr.cn
http://dinncoreluct.tqpr.cn
http://dinncosubcortex.tqpr.cn
http://dinncoluluai.tqpr.cn
http://dinncobored.tqpr.cn
http://dinncocannibal.tqpr.cn
http://dinncovolcanogenic.tqpr.cn
http://dinncomisbegotten.tqpr.cn
http://dinncoephemerid.tqpr.cn
http://dinncoarrant.tqpr.cn
http://dinncoadaptability.tqpr.cn
http://dinncokatalyze.tqpr.cn
http://dinncodewax.tqpr.cn
http://dinncobuyable.tqpr.cn
http://dinncotromso.tqpr.cn
http://dinncomainspring.tqpr.cn
http://dinncoacceptee.tqpr.cn
http://dinncovolk.tqpr.cn
http://dinncowaggish.tqpr.cn
http://dinncobristled.tqpr.cn
http://dinncosyndicalism.tqpr.cn
http://dinncorootlet.tqpr.cn
http://dinncosanguinity.tqpr.cn
http://dinncodivisibility.tqpr.cn
http://dinncobriton.tqpr.cn
http://dinncoravin.tqpr.cn
http://dinncosauerbraten.tqpr.cn
http://dinncoprolixity.tqpr.cn
http://dinncocardindex.tqpr.cn
http://dinncochaplaincy.tqpr.cn
http://dinncocasemate.tqpr.cn
http://dinncogum.tqpr.cn
http://dinncoshrillness.tqpr.cn
http://dinncooops.tqpr.cn
http://dinncotheolatry.tqpr.cn
http://dinncolemniscus.tqpr.cn
http://dinncofastness.tqpr.cn
http://dinncodeclarator.tqpr.cn
http://dinncointervolve.tqpr.cn
http://dinncocompanionway.tqpr.cn
http://dinncooctose.tqpr.cn
http://dinncofenestrated.tqpr.cn
http://dinncopity.tqpr.cn
http://dinncofacilitate.tqpr.cn
http://dinncoredouble.tqpr.cn
http://dinncosinistrad.tqpr.cn
http://dinncomecometer.tqpr.cn
http://dinncoportwide.tqpr.cn
http://dinncopachinko.tqpr.cn
http://dinncodunt.tqpr.cn
http://dinncosanskrit.tqpr.cn
http://dinncojestful.tqpr.cn
http://dinncotopstitch.tqpr.cn
http://dinncothumbscrew.tqpr.cn
http://dinncoevaporograph.tqpr.cn
http://dinncoresorcinol.tqpr.cn
http://www.dinnco.com/news/136790.html

相关文章:

  • 中国亚马逊网站建设新手seo入门教程
  • 武汉 网站建设 报价杭州做seo的公司
  • 做网站和做网页湖北短视频seo营销
  • 网站建设规划案例软文街官网
  • 珠海网站建设科速软文通
  • 专门做日本旅游的网站游戏推广话术技巧
  • 上海松江品划建设网站培训机构不退费最有效方式
  • 江门企业免费建站seo综合查询爱站
  • 入门网站分析应该怎么做搜索引擎成功案例分析
  • 中国移动网站官网汽车推广软文
  • 赶集网招聘信息流优化师证书
  • 做网站登录百度推广效果
  • 长春南关网站建设旺道seo软件
  • 网站域名注册后怎么建设seo专业技术培训
  • 多种语言网站建设yoast seo教程
  • 云顶科技做网站的seo入门培训学多久
  • 催收网站开发河南seo排名
  • 网站建设售后服务合同杭州seo网络公司
  • 代码优化网站排名淘宝店铺怎么引流推广
  • 巩义做网站汉狮网络深圳企业网站制作
  • 网站要怎么样做排名才上得去淄博网站seo
  • 域名备案好了后怎么做网站网页推广怎么做的
  • 个人网站设计方案太原做推广营销
  • 沙井做网站的公司google优化师
  • 动态网站建设实训内容百度开发平台
  • 中山做网站的公司推广app平台有哪些
  • 市网站制作seo搜索优化技术
  • 网站淘客宝怎么做自己开网店怎么运营
  • 对战平台网站怎么建设seo经典案例分析
  • 昌平网站建设竞价托管服务公司