首页 > 其他分享 >实验一:逆向软件设计和开发能力

实验一:逆向软件设计和开发能力

时间:2023-03-05 14:58:43浏览次数:47  
标签:username 逆向 String 软件设计 request 实验 import password response

参考代码来源https://blog.csdn.net/aasd23/article/details/123722532

为完成实验目标,本人在网络上找到了一个基于jsp实现简单登录注册功能的程序,该项目功能基本完善,界面设计美观,值得我们学习。

但经过测试研究发现该项目存在如下缺陷:

①注册的账号不能保存,关闭该程序第二次使用时还需重新注册

②用户注册不存在限制,不符合实际要求

对此,本人对该项目进行了二次开发,对上述问题进行了初步的解决,方式如下:

①由于暂时还没有学习数据库有关的知识内容,参考网上知识使用文件进行有关数据的保存

②在用户注册阶段增加注册码,只有注册码正确才能进行账号的注册,正确注册码为:520shou

 

实验环境:window 10  eclipse

 

二次开发结果如下:

改进代码(主要内容截图):

   

register.jsp

<div class="center">
    <p class="fon">注册界面</p>
    <p>请输入您的用户名和密码进行注册</p>
    <form method="post" action="registerservlet">
        账号:<input type="text"name="username" style="width: 200px;height: 40px" placeholder="请输入账号" > <br>
        密码:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text"name="password" style="width: 200px;height: 40px" placeholder="请输入密码" > <br>
        注册码:<input type="text"name="unlockkey" style="width: 200px;height: 40px" placeholder="请输入注册码" > <br>
        <button type="submit" style="width:80px;height:40px; font-size: 20px" class="clear">注册</button>
        <button type="reset" style="width:80px;height:40px; font-size: 20px" class="clear">重置</button>
        <br>
    </form>
</div>

resigterservlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html; charset=utf-8");
        request.setCharacterEncoding("UTF-8");
        String username =request.getParameter("username");
        String password =request.getParameter("password");
        String unlockkey=request.getParameter("unlockkey");
        if(unlockkey.equals("520shou")) 
        {   
            File file=new File("D:/workspace/Logininterface/userinformation.txt");
            try {
                 BufferedWriter fileWriter=new BufferedWriter(new FileWriter(file,true));
                 fileWriter.write(username+"/"+password);
                 fileWriter.newLine();
                 fileWriter.flush();
                 fileWriter.close();
                 } 
            catch (IOException e) 
                 {
                         System.out.println("输入错误");
                         e.printStackTrace();
                 } 
            }
              
        request.getRequestDispatcher("registersuccess.jsp").forward(request, response);
    }

 

checkservlet.java

package Logininterface;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class checkservlet
 */
@WebServlet("/checkservlet")
public class checkservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final BufferedReader NULL = null;
    private String password;
    private String username;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public checkservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html; charset=utf-8");
        request.setCharacterEncoding("UTF-8");
        String username =request.getParameter("username");
        String password =request.getParameter("password");
        boolean a =checklogin(username,password);
        if(a)
        {
        request.getRequestDispatcher("loginsuccess.jsp").forward(request, response);  
        }
        else
        request.getRequestDispatcher("loginfail.jsp").forward(request, response);
    }
    
    private boolean checklogin(String username, String password) throws IOException {
        // TODO Auto-generated method stub
        boolean flag = false;
        BufferedReader lbd;
            lbd = new BufferedReader(new FileReader("D:/workspace/Logininterface/userinformation.txt"));
            String line = null;
            while ((line = lbd.readLine()) != null)
            {
                String[] datas = line.split("/");
                if (datas[0].equals(username) && datas[1].equals(password)) 
                {
                    flag = true;
                    break;
                }
            }
        return flag;
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

 

 运行结果:

 

 

文件内容(可以直接对文件进行修改完成账号的增删改查)

 

 

 实验感悟

①我们在未来的工作中,对公司原有项目进行二次开发的概率比从头开始进行开发的概率大的多,因此掌握如何实现二次开发的技能是十分重要的

②在研究他人的代码时,相比从上往下一字一句的研究代码,我们更应该先建立一个大致框架,然后在根据这个框架补足细节,这样才能更深刻的理解

③网上很多实现登录注册功能的程序都使用了数据库的知识,做出来的成果具有更广泛的应用性,功能也更多,希望在学完相关知识后能采用数据库进行进一步改进

 

 

 

 

 

 

 

 

标签:username,逆向,String,软件设计,request,实验,import,password,response
From: https://www.cnblogs.com/xyx2003/p/17180553.html

相关文章

  • 软件设计与体系结构第一次分享
    1.单一职责原则:就是对于类来说,一个类应该只负责一项职责,规定一个类应该有且仅有一个引起它变化的原因,否则类应该被拆分,也就是说,接口的职责并不是单一的,而是包含两个职责(......
  • K8S CKA 1.26 模拟环境 实验环境(一键导入) Kubernetest v1.26题库
    K8SCKA1.26考试环境,按照CKA最新原题搭建的,模拟环境已集成考题,可直接模拟练习,做题实操。资料包含:2023年3月最新题库+答案解析+考试笔记+模拟环境+技术支持+在线辅导答疑......
  • Momiria:基于计算机程序模拟的疫情传播实验
    基于计算机程序模拟的疫情传播实验 Momiria​摘要:通过设计计算机程序模拟疫情传播机理,通过调控参数进行对比试验、并对实验数据进行函数拟合、数学建模,由此总结出......
  • 实验1
    #include<stdio.h>intmain(){printf("O\n");printf("<H>\n");printf("II\n");return0;}#include<stdio.h>intmain(){prin......
  • 实验1
    实验任务11.//打印一个字符小人#include<stdio.h>intmain(){ printf("o\n"); printf("<H>\n"); printf("II\n");printf("o\n"); printf("<H>\n"......
  • 静态路由综合实验
    实验要求:1R6为isp,接口IP地址均为公有有地址;该设备只能配置IP地址,之后不能再对其进行任何配置;2R1—R5为局域网,私有P地址192.168.1.0/24,请合理分配;3R1,R2,R4,......
  • 实验一
    #inc#include<stdio.h>intmain(){inti;for(i=1;i<=2;i++){printf("o\n");printf("<H>\n");printf("II\n");}return......
  • 逆向软件设计和开发——留言板系统
    该系统实现了留言板的登陆和注册,留言的增加和读取。采用mysql数据库,把用户的信息(用户名、id(唯一)、密码)和留言(标题、内容、作者昵称、留言时间)分别储存在”yonghu”和”mess......
  • 实验
    test1.c代码#include<stdio.h>intmain(){printf("O\n");printf("<H>\n");printf("II\n");return0;}结果代码#include<stdio.h>......
  • 实验1
    实验任务1实验代码#include<stdio.h>intmain(){ printf("00\n"); printf("<H><H>\n"); printf("IIII\n"); return0;}实验结论实验任......