java產生隨機密碼


package com.oo.liu.demo01;

import java.nio.charset.MalformedInputException;

public class createPassword {
	/**
	 * 此類是隨機生成8位數字、英文(大小寫)、特殊符號的密碼
	 */
	public static void number() {
		/**
		 * 計算字符串
		 */
		int n=0;
		String reference="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm!@#$%^&*()";
	
		char[] strarr=reference.toCharArray();//字符串轉換成字符
		for (int i = 0; i < strarr.length; i++) {
			n++;
		}
		System.out.println("字符串個數:"+n);
		
	}
	public static void passRandom() {
		String pass=null;
		String textString="";
		String reference="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm!@#$%^&*()";
		StringBuffer buffer=new StringBuffer(reference);
		System.out.println(buffer.charAt(23));
		for (int i = 0; i < 8; i++) {
            //隨機產生0-72的數字
			int ran=(int)(Math.random()*72);
            //buffer.charAt()是索引該位置的字符
			textString+=buffer.charAt(ran);
		}
		System.out.println(textString);
	}
	public static void main(String[] args) {
		
		passRandom();
	}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM