java实名认证源代码,java实名认证接口
java源代码是给你一个身份证号,通过面板身份证号的输入,显示出该身份证主人的出生年月,省份,性别等资料
我当初用struts1和hibernate做了个简单的!主要的逻辑代码在下面!数据库里号码对应的城市在网上可以查的到
10年积累的网站制作、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计制作后付款的网站建设流程,更有绥阳免费网站建设让你可以放心的选择与我们合作。
package dao;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Expression;
import entity.Shenfenzhen;
public class IdDao {
private static Configuration configuration = new Configuration().configure() ;
private static SessionFactory sessionFactory =configuration.buildSessionFactory();
private static Session session = null;
public Info query(String s){
Info info = null;
StringBuffer stringBuffer = new StringBuffer(s);
if(s.length()==18){
String end = stringBuffer.substring(17);
//System.out.println(end);
if(!end.matches("\\d||x")){
return null;
}
}
else if(s.length()==15){
stringBuffer.insert(6, "19");
stringBuffer.append("3");
}
int i = Integer.parseInt(stringBuffer.substring(0, 6));
//System.out.println(i);
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Shenfenzhen.class);
criteria.add(Expression.eq("num", i));
ListShenfenzhen list = criteria.list();
String address = null;
try {
address = list.get(0).getAddress();
}catch (Exception e) {
return null;
}
i = Integer.parseInt(stringBuffer.substring(16,17));
String sex = null;
if(i%2==0){
sex = "女";
}else{
sex = "男";
}
//System.out.println(i);
stringBuffer = new StringBuffer(stringBuffer.substring(6, 14));
// stringBuffer.insert(4, "-");
// stringBuffer.insert(7, "-");
//System.out.println(stringBuffer);
String ss = stringBuffer.toString();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String brithday="";
int year=0;
int month =0;
int day =0;
try {
Date date = dateFormat.parse(ss);
//System.out.println(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH)+1;
day = calendar.get(Calendar.DAY_OF_MONTH);
brithday = (String)(year + "年" + month + "月" + day + "日");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
info = new Info(address, brithday, sex);
Calendar c = Calendar.getInstance();
int nowYear = c.get(Calendar.YEAR);
int nowMonth = c.get(Calendar.MONTH);
int nowDay = c.get(Calendar.DAY_OF_MONTH);
if(nowYearyear){
info = null;
}else if(nowYear ==year nowMonthmonth ){
info = null;
}else if(nowYear == year nowMonth==month nowDayday){
info = null;
}
closeSession(session);
return info;
}
// public static void main(String[] args){
// IdDao dao = new IdDao();
// dao.query("342522998711224513");
// System.out.println("x".matches("\\d||x"));
// }
private void closeSession(Session session){
if(session !=null){
session.close();
}
}
}
java验证身份证号码是不是有效源代码
package com.yanlun.starter.utils;
import java.util.regex.Pattern;
/**
* @author 作者:Yan,Email:yanlun0323@163.com
* @version 创建时间:2017年5月26日 上午10:42:09
*/
public class Validation {
public static final Pattern REX_DATE_YYYYMM_PATTERN = Pattern.compile("^[0-9]{6}$");
public static final Pattern REX_DATE_YYYYMMDD_PATTERN = Pattern.compile("^[0-9]{8}$");
// 身份证校验加权因子
public static final Integer[] ID_NUM_FACTOR = new Integer[] { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,
1 };
// 身份证第18位校验码
public static final String[] ID_NUM_PARITY_BIT = new String[] { "1", "0", "X", "9", "8", "7", "6", "5", "4", "3",
"2" };
/*
* 是否空字符串
*
* @param c 文本或其它基本数字类型对象
*/
public static boolean isEmpty(Object c) {
return c == null || c.toString().trim().equals("");
}
/**
* 判断是否为“”式的时期
*
* @param dateStr
* @return
*/
private static boolean isDate6(String dateStr) {
if (isEmpty(dateStr) || !REX_DATE_YYYYMM_PATTERN.matcher(dateStr).matches()) {
return false;
}
return isValidDateRange(date6Split(dateStr));
}
/**
* 判断是否为“YYYYMMDD”式的时期
*
* @param dateStr
* @return
*/
private static boolean isDate8(String dateStr) {
if (isEmpty(dateStr) || !REX_DATE_YYYYMMDD_PATTERN.matcher(dateStr).matches()) {
return false;
}
return isValidDateRange(date8Split(dateStr));
}
private static boolean isLeapYear(Integer year) {
return ((year % 4 == 0) (year % 100 != 0)) || (year % 400 == 0);
}
private static boolean isInvalidYear(Integer year) {
return year 1700 || year 2500;
}
private static boolean isInvalidMonth(Integer month) {
return month 1 || month 12;
}
private static boolean isInvalidDay(Integer day, Integer month, Integer year) {
Integer[] iaMonthDays = new Integer[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (isLeapYear(year))
iaMonthDays[1] = 29;
return day 1 || day iaMonthDays[month - 1];
}
/**
* split date 0-YY,1-MM,2-DD
*
* @param dateStr
* @return
*/
private static Integer[] date6Split(String dateStr) {
final Integer YEAR_BASE = 1900;
Integer year = null, month = null, day = null;
year = YEAR_BASE + Integer.valueOf(dateStr.substring(0, 2));
month = Integer.valueOf(dateStr.substring(2, 4));
day = Integer.valueOf(dateStr.substring(4, 6));
return new Integer[] { year, month, day };
}
/**
* split date 0-YYYY,1-MM,2-DD
*
* @param dateStr
* @return
*/
private static Integer[] date8Split(String dateStr) {
Integer year = null, month = null, day = null;
year = Integer.valueOf(dateStr.substring(0, 4));
month = Integer.valueOf(dateStr.substring(4, 6));
if (dateStr.length() == 8) {
day = Integer.valueOf(dateStr.substring(6, 8));
return new Integer[] { year, month, day };
} else {
return new Integer[] { year, month };
}
}
private static boolean isValidDateRange(Integer[] dateSplitResult) {
Integer year = dateSplitResult[0], month = dateSplitResult[1], day = dateSplitResult[2];
if (isInvalidYear(year))
return false;
if (isInvalidMonth(month))
return false;
if (isInvalidDay(day, month, year))
return false;
return true;
}
/**
* 18位/15位身份证号码校验
*
* @param idNumber
* @return
*/
public static boolean isIdentityCardNum(String idNumber) {
if (isEmpty(idNumber) || (idNumber.length() != 18 idNumber.length() != 15)) {
return false;
}
// initialize
if (idNumber.length() == 18) {
// check date
String date8 = idNumber.substring(6, 14);
if (isDate8(date8) == false) {
return false;
}
int totalMulAiWi = 0;
char charAt;
// check and set value, calculate the totalmulAiWi
for (int i = 0; i 17; i++) {
charAt = idNumber.charAt(i);
if (charAt '0' || charAt '9') {
return false;
}
totalMulAiWi += Integer.valueOf(String.valueOf(charAt)) * ID_NUM_FACTOR[i];
}
// calculate the check digit
String checkDigit = ID_NUM_PARITY_BIT[totalMulAiWi % 11];
// check last digit
if (!checkDigit.equalsIgnoreCase(String.valueOf(idNumber.charAt(17)))) {
return false;
}
} else {// length is 15
// check date
String date6 = idNumber.substring(6, 12);
if (isDate6(date6) == false) {
return false;
}
}
return true;
}
}
用JAVA编写一个对18位身份证的输入验证程序.要求输入的18位数字或最后一位为x时,通过验证,否则不通过.
private static final String onlyNum = "^[0-9]*{1}“;
/**
* 验证身份证号码
* @param id_number
* @return
*/
public static Boolean checkNID(String id_number){
Boolean isRight = false;
if(id_number.length() != 15 id_number.length() != 18){
return false;
}
String string = id_number.substring(0, id_number.length() - 1);
if(!string.matches(onlyNum)){
return false;
}
if(id_number.length() == 15){
return is15IDNumberRight(id_number);
} else if(id_number.length() == 18){
return is18IDNumberRight(id_number);
}
return isRight;
}
JAVA用户注册 (我要源代码)
跑这儿作家庭作业了? 如果连用哪种页面技术都不知道提的话,恐怕别人给你源代码你也看不懂哦,想想别人给你个tapestry、Wicket之类的写的代码,拿给老师肯定挨批的哟(一看就露馅了)。
java,编写一个用户身份验证程序,用户名及密码从键盘输入
你的程序有一点小问题,m的值没改变,我给你改了一下,你看看吧。
import java.util.*;
class User{
private String userName,password;
User(){
System.out.println("输入用户名:");
Scanner reader=new Scanner(System.in);
userName=reader.nextLine();
System.out.println("输入密码:");
Scanner reader1=new Scanner(System.in);
password=reader1.next();
}
void check(){
int m=0;
int n=0;
if(userName.equals("")==true || userName==null)
m=0;
else
m=userName.length();
if(password.equals("12345678")==true)
n=1;
if(m!=0 n==1){
System.out.println("用户名有效");
}else{
System.out.println("用户名无效");
}
}
}
public class Users {
public static void main(String[] args){
User user=new User();
user.check();
}
}
当前文章:java实名认证源代码,java实名认证接口
网页路径:http://scyanting.com/article/phjpsc.html