您的位置:首页 > 产品设计 > UI/UE

用GUI写了一个登录验证(含时间加密)

2015-12-18 13:25 435 查看
最近的四个项目,统一加了一个登录界面,除了验证用户名和密码外,还加了一个到指定时间就不好用的功能,用这个来实现加密。
要点包括:GUIskin的设置,TextField,PasswordField,系统时间的获取等
上个代码吧
using UnityEngine;
using System.Collections;

public class Login : MonoBehaviour {
public Texture bgTexture;
private float widthF = Screen.width;
private float heightF = Screen.height;
public GUIStyle dengluStyle;
public GUIStyle tuichuStyle;
private float btnWidth = 164;
private float btnHeight = 117;
public GUISkin windowSkin;
//帐号
private string _name;
//密码
private string _password;
public string nameInput="";//获取输入的帐号 
public string passwordInput = "";//获取输入的密码

private bool tishi;
void Start(){
_name = "liaoshihua";
_password = "liaoshihua";
}
void OnGUI(){
GUI.DrawTexture(new Rect(0,0,widthF,heightF),bgTexture,ScaleMode.StretchToFill,true,10.0f);
GUI.skin = windowSkin;
nameInput = GUI.TextField(new Rect(690,392,150,30),nameInput);
passwordInput = GUI.PasswordField(new Rect(690,428,150,30),passwordInput,"*"[0],16);

if(GUI.Button(new Rect(550,440,btnWidth,btnHeight),"",dengluStyle)){

int yearStr = System.DateTime.Now.Year;
if(yearStr>2012){
return;
}
int monthStr = System.DateTime.Now.Month;
if(monthStr>10){
return;
}
int dayStr = System.DateTime.Now.Day;
if(dayStr>15){
return;
}

if(_name == nameInput && _password == passwordInput){
Application.LoadLevel(1);
tishi = false;
}else{
Debug.Log("用户名或密码错误");
tishi = true; 


}
if(tishi){
GUI.Label(new Rect(850,392,150,30),"Try Again"); 
}

if(GUI.Button(new Rect(710,440,btnWidth,btnHeight),"",tuichuStyle)){
Application.Quit();
}


}
复制代码
转自:http://ilaoxu.com/gui-write-a-lo
... ing-encryption.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d unity