コード例 #1
0
  public String forgotPassword() {
    System.out.println("in forgot password...." + email);
    int flag = CheckValidEmail.validity(email);
    if (email.equals("")) {
      addActionError("Please fill email ID");
      return ERROR;
    }
    if (flag == 1) {
      addActionError("Please enter a valid email ID, entered Email is not registered with us");
      return ERROR;
    } else {
      StringBuffer sb = new StringBuffer();
      for (int x = 0; x < 5; x++) {
        sb.append((char) ((int) (Math.random() * 26) + 97));
      }
      System.out.println(sb.toString());
      setFrom("*****@*****.**");
      setSenderPassword("dipRituSuv");
      setBody(
          "Your password is reset to " + sb.toString() + " \nPlease sign in with it the next time");
      try {
        Session session =
            Session.getDefaultInstance(
                properties,
                new javax.mail.Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(from, getSenderPassword());
                  }
                });

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
        message.setSubject("Forgot Password");
        message.setText(body);
        Transport.send(message);
      } catch (Exception e) {
        e.printStackTrace();
      }
      String encryptedPassword = PasswordEncryption.EncryptPassword(sb.toString());
      try {
        java.sql.Connection con = DBManager.getConnection();
        DBManager.useDataBase(con);
        sqlQuery = "update customer set password =? where userName=?;";
        statement = con.prepareStatement(sqlQuery);
        statement.setString(1, encryptedPassword);
        statement.setString(2, CheckValidEmail.getUserName());
        res = statement.executeUpdate();
      } catch (Exception e) {
        e.printStackTrace();
      }
      return SUCCESS;
    }
  }
コード例 #2
0
  public String forgotUserName() {
    System.out.println("in forgot user name...." + email);
    int flag = CheckValidEmail.validity(email);
    if (email.equals("")) {
      addActionError("Please fill email ID");
      return ERROR;
    }
    if (flag == 1) {
      addActionError("Please enter a valid email ID, entered Email is not registered with us");
      return ERROR;
    } else {
      System.out.println(CheckValidEmail.getUserName());
      setFrom("*****@*****.**");
      setSenderPassword("dipRituSuv");
      setBody(
          "Your user name is "
              + CheckValidEmail.getUserName()
              + " \nPlease sign in with it the next time");
      try {
        Session session =
            Session.getDefaultInstance(
                properties,
                new javax.mail.Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(from, getSenderPassword());
                  }
                });

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
        message.setSubject("Forgot User Name");
        message.setText(body);
        Transport.send(message);
      } catch (Exception e) {
        e.printStackTrace();
      }
      return SUCCESS;
    }
  }