英文:
Trying to extract password from auto generated email. But it is failing in various combinations
问题
以下是您提供的内容的中文翻译:
我正在尝试从电子邮件中提取密码,但无法成功。当从邮件中提取密码时,邮件会包含HTML字符。当邮件实用程序返回电子邮件的内容时,它应该适用于以下所有密码组合。
String s = "Y5y>eAy&";
String s2 = "jO3S>Eu1</p>";
String s4 = "jO3SEu1!";
String s5 = "u8P>SIzk";
String s6 = "83Pp>epn";
String s7 = "83Pp>epn";
String s3 = "<p>已为您的用户帐户创建了临时密码。</p>" +
"<p>用户名:abc+1676532236813@abc.com</p>" +
"<p>密码:83Pp>epn</p>" +
"<p>使用提供的URL登录到平台以完成您的用户帐户设置。</p>\n" +
"<p><a href=\"https://example.com/login\">https://login-dev.example.com/login</a></p>";
我已经尝试了以下代码,但它没有起作用。
int index = s3.indexOf("密码:");
String password = "";
// System.out.println("first is " + password);
password = s3.substring(index + 4, index + 15);
System.out.println("index of / is " + password.indexOf("/"));
if (password.indexOf("/") == 11) {
password = s3.substring(index + 4, index + 12);
password = password.replaceAll("(.*?)|(&.*?;)|([ ]{2,})", "");
} else {
System.out.println("你好");
password = s3.substring(index + 4, index + 10);
password = password.replaceAll("(.*?)|(&.*?;)|([ ]{2,})", "");
}
password = password.replace(">", "");
System.out.println(password);
有人可以帮助我吗?
英文:
I am trying to extract password from email but unable to do so. The mail when extracted for password will have html chars. when the mail utility is returning the content of email
It should work for all following combinations of passwords
String s = "Y5y&gt;eAy&amp;";
String s2 = "jO3S&gt;Eu1</p>";
String s4 = "jO3SEu1!";
String s5 = "u8P&gt;SIzk";
String s6 = "83Pp>epn";
String s7 = "83Pp&gt;epn";
String s3 = "<p>A temporary password has been created for your user account.</p>" +
"<p>User Name: abc+1676532236813@abc.com</p>" +
"<p>Password: 83Pp&gt;epn</p>" +
"<p>Log into the platform with the provided URL to complete your user account set up.</p>\n" +
"<p><a href=\"https://example.com/login\">https://login-dev.example.com/login</a></p>";
I have tried following code but it is not working
int index = s3.indexOf("Password: ");
String password = "";
// System.out.println("first is "+password);
password = s3.substring(index + 11, index + 24);
System.out.println("index of / is " + password.indexOf("/"));
if (password.indexOf("/") == 12) {
password = s3.substring(index + 11, index + 22);
password = password.replaceAll("(.*?)|(&.*?;)|([ ]{2,})", "");
} else {
System.out.println("hello");
password = s3.substring(index + 11, index + 19);
password = password.replaceAll("(.*?)|(&.*?;)|([ ]{2,})", "");
}
password = password.replace("&gt;", "");
System.out.println(password);
Can anyone help me here
答案1
得分: 1
以下是翻译好的部分:
String password = s3.substring(s3.indexOf("<p>Password: ") + 13);
password = password.substring(0, password.indexOf("</p>"));
System.out.println(password);
The code searches for the String `<p>Password: `, removes everything infront of it and afterwards remove all and including after `</p>`.
I don't know if I understood your question correct, but if you want to unescape HTML characters afterwards, you could use the StringEscapeUtils class:
String withCharacters = StringEscapeUtils.unescapeHtml(password);
System.out.println(withCharacters);
Simply add it before the System.out.
Of course, with this the solution, the String before the password has to always be the same.
英文:
You can try something like this:
String password = s3.substring(s3.indexOf("<p>Password: ") + 13);
password = password.substring(0, password.indexOf("</p>"));
System.out.println(password);
The code searches for the String <p>Password:
, removes everything infront of it and afterwards remove all and including after </p>
.
I don´t know if I understood your question correct, but if you want to unescape HTML characters afterwards, you could use the StringEscapeUtils class:
String withCharacters = StringEscapeUtils.unescapeHtml(password);
System.out.println(withCharacters);
Simply add it before the System.out.
Of course, with this the solution, the String before the password has to always be the same.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论