Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:58:19+00:00 2026-06-06T14:58:19+00:00

Possible Duplicate: Password protecting my android app (the simple way) Edit: I founded what

  • 0

Possible Duplicate:
Password protecting my android app (the simple way)

Edit:

I founded what i want here: Password protecting my android app (the simple way)

old

(I have a TextField named password. If a user enters the correct password 123, upon clicking a button I want the user to go to another activity. If a wrong password is entered, a message such as "Wrong password!" should be displayed. The actual password itself is found in a file located at /sdcard/Android/password.txt.

How can I create such functionality?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:58:20+00:00Added an answer on June 6, 2026 at 2:58 pm

    You need to cover a lot of ground here UI, Security etc. so I will give you a brief overview on the steps you need to get done.

    You need activities or dialogs for the UI’s, getting an initial password and checking the password both should have

    TextView that uses the password attribute set (hide characters)

    Button(s) that allows the user to cancel or select ok with on click listeners attached

    To store/get the password then use something similar to this instead of sdcard and a txt file Getting a password from shared preferences, you can use the shared preferences editor to store it as well. This adds a bit of security but not much

    In general what you should store is not the password itself, but you should really store a token for added security, here is one class that can do that for you

    import java.security.MessageDigest;
    
    public class PasswordToken {
    
        static public String makeDigest(String password) 
        {
             String hexStr = "";
    
            try {
                MessageDigest md = MessageDigest.getInstance("SHA1");
                md.reset();
                byte[] buffer = password.getBytes();
                md.update(buffer);
                byte[] digest = md.digest();
    
    
                for (int i = 0; i < digest.length; i++) {
                    hexStr +=  Integer.toString( ( digest[i] & 0xff ) + 0x100, 16).substring( 1 );
    
            } 
            } catch(Exception e) // If the algo is not working for some reason on this device
                                 // we have to use the strings hash code, which 
                                 // could allow duplicates but at least allows tokens
            {
                hexStr = Integer.toHexString(password.hashCode()); 
            }
    
            return hexStr;
        }
    
        static public boolean validate(String password, String token) 
        {
             String digestToken = "";
             String simpleToken = "";
    
             digestToken = makeDigest(password);
    
             if (0 == digestToken.compareTo(token)) 
                 return true; 
    
             if (0 == simpleToken.compareTo(token))
                 return true;
    
             return false; 
        }
    }
    

    So to store a password when you clicked on your ok button

     PasswordTextView.getText();
      String token = PasswordToken.makeDigest(password);
      //... store TOKEN using the shared preferences editor 
    

    To check a password when your user wanted to login

    PasswordTextView.GetText();
      String token = PasswordToken.makeDigest(password);
      //... GET token using the shared preferences 
    
      if (PasswordToken.validate(token))
         Start your new activity
      else
         tell your user to try again 
    

    You can use startActivity or startActivityForResult to start another activity and look at overiding the Dialog class to do the UI bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Best way to store password in database I have a database (mySQL)
Possible Duplicate: Accessing Password Protected Network Drives in Windows in C#? I have ComputerA
Possible Duplicate: In MySQL workbench what is username/password for connection? I have phpmyadmin running
Possible Duplicate: Password Strength Meter Hi I have created a password meter script which
Possible Duplicate: Require a password to uninstall/remove application Hello everyone, I want to develop
Possible Duplicate: Making a password lock for an app? hi i am working on
Possible Duplicate: Query about Html <input type=password> tag…? I want change the character displayed
Possible Duplicate: Disable browser 'Save Password' functionality In my application, I have a login
Possible Duplicate: How to create a file in android? I have a game that
Possible Duplicate: Disable browser ‘Save Password’ functionality Is there a standard way to prevent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.