Log-In page with hashed password











up vote
0
down vote

favorite












I am quite new in Android development and hereby I would like to ask you for some help. Basically I have created the text fields of a Android Log-in page (username field & password field) and it works well without hashing a password. But now I want to use SHA256. My knowledge is still not enough to put those two together. So as follows:



public static String SHA256 (String text) throws NoSuchAlgorithmException {

MessageDigest md = MessageDigest.getInstance("SHA-256");

md.update(text.getBytes());
byte digest = md.digest();

String hashedpass = Base64.encodeToString(digest, Base64.DEFAULT);
}


private JSONObject buidJsonObject() throws JSONException {

JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("Username", etName.getText().toString()); // <- here I get directly what I have typed in
jsonObject.accumulate("Password", hashedpass); // <- here I want to have it hashed with SHA256.

return jsonObject;
}


Could you help me with these? Thank you










share|improve this question
























  • looks like you are missing Java basics about how to use methods
    – Vladyslav Matviienko
    Nov 9 at 8:31










  • yes, this is true
    – V B
    Nov 9 at 8:33










  • this means that you should pass some basic Java training before starting something like you are trying to achieve. If you don't do that, you will get 1000 more questions like this.
    – Vladyslav Matviienko
    Nov 9 at 8:34










  • yes, thank you for your advise. I do this in the moment, my problem is to understand the definitions public/static/private and what can be used where. It is quite different than embedded C
    – V B
    Nov 9 at 8:37










  • Do you send this login info to a server? What do you then hope to gain by hashing the password?
    – Henry
    Nov 9 at 9:27















up vote
0
down vote

favorite












I am quite new in Android development and hereby I would like to ask you for some help. Basically I have created the text fields of a Android Log-in page (username field & password field) and it works well without hashing a password. But now I want to use SHA256. My knowledge is still not enough to put those two together. So as follows:



public static String SHA256 (String text) throws NoSuchAlgorithmException {

MessageDigest md = MessageDigest.getInstance("SHA-256");

md.update(text.getBytes());
byte digest = md.digest();

String hashedpass = Base64.encodeToString(digest, Base64.DEFAULT);
}


private JSONObject buidJsonObject() throws JSONException {

JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("Username", etName.getText().toString()); // <- here I get directly what I have typed in
jsonObject.accumulate("Password", hashedpass); // <- here I want to have it hashed with SHA256.

return jsonObject;
}


Could you help me with these? Thank you










share|improve this question
























  • looks like you are missing Java basics about how to use methods
    – Vladyslav Matviienko
    Nov 9 at 8:31










  • yes, this is true
    – V B
    Nov 9 at 8:33










  • this means that you should pass some basic Java training before starting something like you are trying to achieve. If you don't do that, you will get 1000 more questions like this.
    – Vladyslav Matviienko
    Nov 9 at 8:34










  • yes, thank you for your advise. I do this in the moment, my problem is to understand the definitions public/static/private and what can be used where. It is quite different than embedded C
    – V B
    Nov 9 at 8:37










  • Do you send this login info to a server? What do you then hope to gain by hashing the password?
    – Henry
    Nov 9 at 9:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am quite new in Android development and hereby I would like to ask you for some help. Basically I have created the text fields of a Android Log-in page (username field & password field) and it works well without hashing a password. But now I want to use SHA256. My knowledge is still not enough to put those two together. So as follows:



public static String SHA256 (String text) throws NoSuchAlgorithmException {

MessageDigest md = MessageDigest.getInstance("SHA-256");

md.update(text.getBytes());
byte digest = md.digest();

String hashedpass = Base64.encodeToString(digest, Base64.DEFAULT);
}


private JSONObject buidJsonObject() throws JSONException {

JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("Username", etName.getText().toString()); // <- here I get directly what I have typed in
jsonObject.accumulate("Password", hashedpass); // <- here I want to have it hashed with SHA256.

return jsonObject;
}


Could you help me with these? Thank you










share|improve this question















I am quite new in Android development and hereby I would like to ask you for some help. Basically I have created the text fields of a Android Log-in page (username field & password field) and it works well without hashing a password. But now I want to use SHA256. My knowledge is still not enough to put those two together. So as follows:



public static String SHA256 (String text) throws NoSuchAlgorithmException {

MessageDigest md = MessageDigest.getInstance("SHA-256");

md.update(text.getBytes());
byte digest = md.digest();

String hashedpass = Base64.encodeToString(digest, Base64.DEFAULT);
}


private JSONObject buidJsonObject() throws JSONException {

JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("Username", etName.getText().toString()); // <- here I get directly what I have typed in
jsonObject.accumulate("Password", hashedpass); // <- here I want to have it hashed with SHA256.

return jsonObject;
}


Could you help me with these? Thank you







java android sha256






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 10:13









Kling Klang

32.2k156287




32.2k156287










asked Nov 9 at 8:22









V B

1




1












  • looks like you are missing Java basics about how to use methods
    – Vladyslav Matviienko
    Nov 9 at 8:31










  • yes, this is true
    – V B
    Nov 9 at 8:33










  • this means that you should pass some basic Java training before starting something like you are trying to achieve. If you don't do that, you will get 1000 more questions like this.
    – Vladyslav Matviienko
    Nov 9 at 8:34










  • yes, thank you for your advise. I do this in the moment, my problem is to understand the definitions public/static/private and what can be used where. It is quite different than embedded C
    – V B
    Nov 9 at 8:37










  • Do you send this login info to a server? What do you then hope to gain by hashing the password?
    – Henry
    Nov 9 at 9:27


















  • looks like you are missing Java basics about how to use methods
    – Vladyslav Matviienko
    Nov 9 at 8:31










  • yes, this is true
    – V B
    Nov 9 at 8:33










  • this means that you should pass some basic Java training before starting something like you are trying to achieve. If you don't do that, you will get 1000 more questions like this.
    – Vladyslav Matviienko
    Nov 9 at 8:34










  • yes, thank you for your advise. I do this in the moment, my problem is to understand the definitions public/static/private and what can be used where. It is quite different than embedded C
    – V B
    Nov 9 at 8:37










  • Do you send this login info to a server? What do you then hope to gain by hashing the password?
    – Henry
    Nov 9 at 9:27
















looks like you are missing Java basics about how to use methods
– Vladyslav Matviienko
Nov 9 at 8:31




looks like you are missing Java basics about how to use methods
– Vladyslav Matviienko
Nov 9 at 8:31












yes, this is true
– V B
Nov 9 at 8:33




yes, this is true
– V B
Nov 9 at 8:33












this means that you should pass some basic Java training before starting something like you are trying to achieve. If you don't do that, you will get 1000 more questions like this.
– Vladyslav Matviienko
Nov 9 at 8:34




this means that you should pass some basic Java training before starting something like you are trying to achieve. If you don't do that, you will get 1000 more questions like this.
– Vladyslav Matviienko
Nov 9 at 8:34












yes, thank you for your advise. I do this in the moment, my problem is to understand the definitions public/static/private and what can be used where. It is quite different than embedded C
– V B
Nov 9 at 8:37




yes, thank you for your advise. I do this in the moment, my problem is to understand the definitions public/static/private and what can be used where. It is quite different than embedded C
– V B
Nov 9 at 8:37












Do you send this login info to a server? What do you then hope to gain by hashing the password?
– Henry
Nov 9 at 9:27




Do you send this login info to a server? What do you then hope to gain by hashing the password?
– Henry
Nov 9 at 9:27

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222094%2flog-in-page-with-hashed-password%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222094%2flog-in-page-with-hashed-password%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

JBPM : POST request for execute process go wrong