Android: Simple Password Generator
Submitted by razormist on Tuesday, January 9, 2018 - 15:09.
In this tutorial we will try to create a Simple Password Generator Using Android. Android is most commonly comes installed on a variety of smartphones and tablets, and even in TV. Android is an open source so that developer find it easy to develop and expand new features. So let's do the coding...
There you have it we successfully created a Simple Password Generator using Android. I hope that this simple tutorial help you to your projects. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Getting Started:
First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things. Here's the link for the Android Studio https://developer.android.com/studio/index.html.Layout Design
We will now add some layout to the application. Just kindly copy the code below and paste it inside the code editor- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.razormist.simplepaswordgenerator.MainActivity">
- <TextView
- android:id="@+id/tv_password"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:fontFamily="monospace"
- android:textSize="40sp"
- android:gravity="center"
- android:layout_centerInParent="true"
- android:layout_marginBottom="40dp"
- android:hint="Password"/>
- android:id="@+id/btn_generate"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:layout_below="@+id/tv_password"
- android:text="Generate"/>
- </RelativeLayout>
Android Manifest File
The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code.- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.razormist.simplepaswordgenerator">
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity"
- android:configChanges="orientation"
- android:screenOrientation="portrait">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
The Main Function
This code contains the main function of the application. This code will randomly display a certain character the generate button is clicked.- package com.razormist.simplepaswordgenerator;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import java.util.Random;
- public class MainActivity extends AppCompatActivity {
- TextView tv_passowrd;
- Button btn_generate;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- tv_passowrd = (TextView)findViewById(R.id.tv_password);
- @Override
- int length = 12;
- tv_passowrd.setText(GetPassword(length));
- }
- });
- }
- char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
- StringBuilder stringBuilder = new StringBuilder();
- for(int i = 0; i < length; i++){
- char c = chars[rand.nextInt(chars.length)];
- stringBuilder.append(c);
- }
- return stringBuilder.toString();
- }
- }
Comments
Add new comment
- Add new comment
- 2032 views