首页 > 解决方案 > 我从github下载了一个spring boot项目,PHPMYADMIN中的密码有问题(密码变成密码,密码)

问题描述

案例场景:我注册并使用“duck”作为密码。如果我注销并想再次登录,它会给我一条错误消息。为什么?在 phpmyadmin 中,密码是duck,duck,这样我就可以访问网站了。我想解决这个问题。但是怎么做?(我在这里放了一些代码,如果你需要更多让我知道)

用户控制器

package com.mmmcarrental.app.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

import com.mmmcarrental.app.controllers.beans.LoginBean;
import com.mmmcarrental.app.models.entity.Client;
import com.mmmcarrental.app.models.service.interfaces.IClientService;

@Controller
public class UserController {

    @Autowired
        IClientService clientService;
        
        @GetMapping("/user/login")
        public String showLoginForm (HttpServletRequest request, HttpServletResponse response, Model model) {
            return "/user/login/index";
        }
        
        @PostMapping ("/user/login")
        public String loginProcess (HttpServletRequest request, HttpServletResponse response, @ModelAttribute("login") LoginBean login, HttpSession session) {
            
            Client client = clientService.findByUser(login.getUserName());
            
            if (null != login && client != null && client.getPassword().equals(login.getPassword())) {
                session.setAttribute("client", client);
            } else {
                session.setAttribute("error_userAuthentification", "Username or password is wrong!");
                return "user/login/index";
            }
            return "redirect:/";
        }
        @GetMapping("/user/logout")
        public String showLogoutForm (HttpSession session) {
         session.invalidate();{
            return "/user/logout/index";
         }
        }
        
        
        @GetMapping("/user/registration")
        public String showRegisterForm (HttpServletRequest request, HttpServletResponse response) {
            Client client = new Client();
            HttpSession session = request.getSession(true);
            session.setAttribute("tempClient", client);
            return "user/registration/index";
        }
        
        @PostMapping("/user/registration")
        public String registerProcess (HttpSession session, @ModelAttribute ("registration") Client newClient) {
    
            if (Utils.isValid(newClient)) {
                if (!exists(newClient)) {
                    clientService.save(newClient);
                } else {
                    session.setAttribute("error_usernameTaken", "Sorry, this Username already exists");
                    return "user/registration/index";
                }
            } else {
                session.setAttribute("errorMessage", "Sorry, make sure to fill all the fields before continue");
                return "user/registration/index";
                
            }
            session.setAttribute("client", newClient);
            session.removeAttribute("tempClient");
            return "redirect:/";
        }
        
            
        public boolean exists (Client client) {
            if (clientService.findByUser(client.getUserName()) != null) {
                return true;
            }   
            return false;
        }
    }

客户端.JAVA

 package com.mmmcarrental.app.models.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.*;

@Entity
@Table(name = "clients")
public class Client implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_cliente")
    private Long idClient;

    @NotEmpty(message = "El campo no es opcional")
    private String name;
    
    @NotEmpty(message = "El campo no es opcional")
    private String surname;
    
    @NotEmpty(message = "El campo no es opcional")
    @Column(name = "id_number")
    private String idNumber;
    
    @NotEmpty(message = "El campo no es opcional")
    @Column(name = "phone_number")
    private String phoneNumber;
    
    @NotEmpty(message = "El campo no es opcional")
    @Email(message = "formato incorrecto")
    private String email;
    
    private String address;
    private String postCode;
    private String city;
    private String country;
    
    
    @NotEmpty(message = "El campo no es opcional")
    @Column(name = "user_name")
    private String userName;
    
    @NotEmpty(message = "El campo no es opcional")
    private String password;

    public Client() {

    }

    public Client(@NotEmpty(message = "El campo no es opcional") String name,
            @NotEmpty(message = "El campo no es opcional") String surname,
            @NotEmpty(message = "El campo no es opcional") String idNumber,
            @NotEmpty(message = "El campo no es opcional") String phoneNumber,
            @NotEmpty(message = "El campo no es opcional") @Email(message = "formato incorrecto") String email,
            String address, String postCode, String city, String country,
            @NotEmpty(message = "El campo no es opcional") String userName,
            @NotEmpty(message = "El campo no es opcional") String password) {
        super();
        this.name = name;
        this.surname = surname;
        this.idNumber = idNumber;
        this.phoneNumber = phoneNumber;
        this.email = email;
        this.address = address;
        this.postCode = postCode;
        this.city = city;
        this.country = country;
        this.userName = userName;
        this.password = password;
    }

    public Long getIdClient() {
        return idClient;
    }

    public void setIdClient(Long idClient) {
        this.idClient = idClient;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }



    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPostCode() {
        return postCode;
    }

    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String user) {
        this.userName = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

} 

注册.HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{base}">

<head>
<title>Register</title>
</head>

<div layout:fragment="page_content" id="page_content" class="container h-100 bg-white overflow-hidden">


    <!-- NEW REGISTRATION FORM -->

    <div class="row align-items-center h-100">
        <div class="col-sm-9 col-md-7 col-lg-7 mx-auto">
            <div class="card my-5">
                <div class="card-body">
                    <h5 class="card-title text-center">Registrazione</h5>
                    <form th:action="@{/user/registration}" th:object="${client}" method="post">
                        <div class="row form-row px-0">
                            <div class="form-group col-lg-6">
                                <label for="inputName">Nome</label>
                                <input type="text" id="inputName" name="name" class="form-control" placeholder="Nome" required autofocus>
                            </div>

                            <div class="form-group col-lg-6">
                                <label for="inputSurname">Cognome</label>
                                <input type="text" id="inputSurname" name="surname" class="form-control" placeholder="Cognome" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputAddress">Indirizzo</label>
                            <input type="text" id="inputAddress" name="address" class="form-control" placeholder="Indirizzo" required>
                        </div>
                        <div class="row form-row px-0">
                            <div class="form-group col-lg-4">
                                <label for="inputPostCode">CAP</label>
                                <input type="text" id="inputPostCode" name="postCode" class="form-control" placeholder="CAP" required autofocus>
                            </div>
                            <div class="form-group col-lg-4">
                                <label for="inputCity">Città</label>
                                <input type="text" id="inputCity" name="city" class="form-control" placeholder="Città" required autofocus>
                            </div>
                            <div class="form-group col-lg-4">
                                <label for="inputCountry">Nazione</label>
                                <input type="text" id="inputCountry" name="country" class="form-control" placeholder="Nazione" required autofocus>
                            </div>
                        </div>
                        <div class="row form-row px-0">
                            <div class="form-group col-lg-6">
                                <label for="inputPhoneNumber">Cellulare</label>
                                <input type="text" id="inputPhoneNumber" name="phoneNumber" class="form-control" placeholder="Cellulare" required autofocus>
                            </div>

                            <div class="form-group col-lg-6">
                                <label for="inputID">Numero della Patente</label>
                                <input type="text" id="inputID" name="idNumber" class="form-control" placeholder="Numero della Patente" required>
                            </div>

                        </div>
                        <div class="form-group">
                            <label for="inputEmail">Email</label>
                            <input type="email" id="inputEmail" name="email" class="form-control" placeholder="Email" required>
                        </div>
                        <div class="row form-row px-0">
                            <div class="form-group col-lg-6">
                                <label for="inputUsername">Username</label>
                                <input type="text" id="inputUsername" name="userName" class="form-control" placeholder="Username" required autofocus>
                                <small th:if="${session.error_usernameTaken != null}" th:text="${session.error_usernameTaken}" id="passwordHelp" class="text-danger"></small>
                            </div>
                        </div>
                        <div class="row form-row px-0">
                            <div class="form-group col-lg-6">
                                <label for="inputPassword">Password</label>
                                <input type="password" id="inputPassword" name=password class="form-control" placeholder="Password" required>
                            </div>
                            <div class="form-group col-lg-6">
                                <label for="inputPassword">Conferma Password</label>
                                <input type="password" id="inputPassword" name=password class="form-control" placeholder="Conferma Password" required>
                            </div>
                        </div>
                        <div class="form-group pl-4">
                            <input class="form-check-input" type="checkbox" value="" id="defaultCheck1" required>
                            <label class="form-check-label" for="defaultCheck1"> Avrò almeno 18 anni al momento del noleggio </label>
                        </div>
                        <button class="btn btn-lg btn-google btn-block text-uppercase" type="submit"> <i class="fas fa-user-circle mr-2"></i> Registrati
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>


</div>

<th:block layout:fragment="scripts">
    <script type="text/javascript">
        console.log('Hello World');
    </script>
</th:block>

标签: javahtmldatabasephpmyadminpasswords

解决方案


推荐阅读