尝试从自动生成的电子邮件中提取密码。但在各种组合中都失败了。

huangapple go评论149阅读模式
英文:

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&gt;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("(.*?)|(&amp;.*?;)|([ ]{2,})", "");
} else {
    System.out.println("你好");
    password = s3.substring(index + 4, index + 10);
    password = password.replaceAll("(.*?)|(&amp;.*?;)|([ ]{2,})", "");
}
password = password.replace("&gt;", "");
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 = &quot;Y5y&amp;gt;eAy&amp;amp;&quot;;
String s2 = &quot;jO3S&amp;gt;Eu1&lt;/p&gt;&quot;;
String s4 = &quot;jO3SEu1!&quot;;
String s5 = &quot;u8P&amp;gt;SIzk&quot;;
String s6 = &quot;83Pp&gt;epn&quot;;
String s7 = &quot;83Pp&amp;gt;epn&quot;;

String s3 = &quot;&lt;p&gt;A temporary password has been created for your user account.&lt;/p&gt;&quot; +
                &quot;&lt;p&gt;User Name:  abc+1676532236813@abc.com&lt;/p&gt;&quot; +
                &quot;&lt;p&gt;Password: 83Pp&amp;gt;epn&lt;/p&gt;&quot; +
                &quot;&lt;p&gt;Log into the platform with the provided URL to complete your user account set up.&lt;/p&gt;\n&quot; +
                &quot;&lt;p&gt;&lt;a href=\&quot;https://example.com/login\&quot;&gt;https://login-dev.example.com/login&lt;/a&gt;&lt;/p&gt;&quot;;

I have tried following code but it is not working

int index = s3.indexOf(&quot;Password: &quot;);
        String password = &quot;&quot;;
//        System.out.println(&quot;first is &quot;+password);
        password = s3.substring(index + 11, index + 24);
        System.out.println(&quot;index of / is &quot; + password.indexOf(&quot;/&quot;));


        if (password.indexOf(&quot;/&quot;) == 12) {
            password = s3.substring(index + 11, index + 22);
            password = password.replaceAll(&quot;(.*?)|(&amp;.*?;)|([ ]{2,})&quot;, &quot;&quot;);
        } else {
            System.out.println(&quot;hello&quot;);
            password = s3.substring(index + 11, index + 19);
            password = password.replaceAll(&quot;(.*?)|(&amp;.*?;)|([ ]{2,})&quot;, &quot;&quot;);
        }
        password = password.replace(&quot;&amp;gt;&quot;, &quot;&quot;);
        System.out.println(password);

Can anyone help me here

答案1

得分: 1

以下是翻译好的部分:

String password = s3.substring(s3.indexOf("&lt;p&gt;Password: ") + 13);
password = password.substring(0, password.indexOf("&lt;/p&gt;"));
System.out.println(password);
The code searches for the String `&lt;p&gt;Password: `, removes everything infront of it and afterwards remove all and including after `&lt;/p&gt;`.
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(&quot;&lt;p&gt;Password: &quot;) + 13);
password = password.substring(0, password.indexOf(&quot;&lt;/p&gt;&quot;));
System.out.println(password);

The code searches for the String &lt;p&gt;Password: , removes everything infront of it and afterwards remove all and including after &lt;/p&gt;.

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.

huangapple
  • 本文由 发表于 2023年2月16日 17:29:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定