能夠選擇鏈接本地服務器,或者雲服務器。html
參考源代碼 : https://www.cnblogs.com/wuzhang/p/wuzhang20141202.html前端
/****************************** * 1,新增數據庫的操做 * 2,對用戶名和密碼採用MD5加密技術 * 3,完善登陸和註冊的邏輯判斷 * @Author wuzhang * 2014/12/4 *****************************/ using UnityEngine; using System.Collections; using UnityEngine.UI; using AssemblyCSharp; using System.Text; using System.Security.Cryptography; using System; using System.Data; using MySql.Data; using MySql.Data.MySqlClient;
public class login : MonoBehaviour { //Toggle public Toggle remPasswd; private Toggle fogPasswd; //註冊信息 public InputField inputName; public InputField inputPaswd; //sql全局操做對象 SqlAccess sql = new SqlAccess(); // <-- 另外一個類 void Start() { DataSet ds = sql.SelectAll("user"); sql.ReadDs(ds); } /// 登陸事件 void OnCLick() { //MD5加密 byte[] result = Encoding.Default.GetBytes(inputPaswd.text); //inputPaswd.text爲輸入密碼的文本框 MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); // 加密預備 Debug.Log ("Md5:"+BitConverter.ToString(output));
string Md5Passwd = BitConverter.ToString(output).Replace("-",""); Debug.Log(sql.ExistOrNot("select * from user where name = " + "'"+inputName.text+"'" +"and passwd = '"+Md5Passwd+"'"));
//加密套路
DataSet ds = sql.ExistOrNot("select * from user where name = " + "'"+inputName.text+"'" +"and passwd = '"+Md5Passwd+"'"); Debug.Log ("檢索到:"+ds.Tables[0].Rows.Count);
if(ds.Tables[0].Rows.Count > 0) { Application.LoadLevel("test1"); } else { Debug.Log ("登陸失敗!"); } }
// Update is called once per frame void Update () { //若是選中記住密碼 if(remPasswd.isOn) { //填充數據,在這裏僅僅是模擬,若是你們想作的真實,能夠寫個配置文件 inputPaswd.text = "123456"; # 能夠不必 } else { inputPaswd.text = inputPaswd.text; } }
///註冊事件
void regist() { //若是能夠的或直接將數據寫入數據庫在這裏咱們僅僅模擬下功能就好了 if(inputName.text!=""&&inputPaswd.text!="") { //MD5加密 byte[] result = Encoding.Default.GetBytes(inputPaswd.text); //tbPass爲輸入密碼的文本框 MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); Debug.Log ("Md5:"+BitConverter.ToString(output)); string Md5Passwd = BitConverter.ToString(output).Replace("-",""); //tbMd5pass爲輸出加密文本的文本框
Debug.Log(Md5Passwd); // 加密套路
Debug.Log(sql.ExistOrNot("select * from user where name = " + "'"+inputName.text+"'" +"and passwd = '"+Md5Passwd+"'")); DataSet ds = sql.ExistOrNot("select * from user where name = " + "'"+inputName.text+"'" +"and passwd = '"+Md5Passwd+"'"); Debug.Log ("檢索到:"+ds.Tables[0].Rows.Count);
if(ds.Tables[0].Rows.Count > 0) { Debug.Log ("該用戶已存在,請從新輸入!"); } else { sql.InsertInto("user",new string[]{"name","passwd"},new string[]{inputName.text,Md5Passwd}); //關鍵值加密32位 string keyStr = "11234567890123456789012345678901"; Debug.Log("註冊成功"); Encryption encrytion = new Encryption(); string encryptionName = encrytion.encryptionContent(inputName.text,keyStr); Debug.Log ("Name After Encryption:"+encryptionName); Debug.Log ("Name After DeEncryption:"+encrytion.decipheringContent(encryptionName,keyStr)); string encryptionPasswd = encrytion.encryptionContent(inputPaswd.text,keyStr); Debug.Log ("Passwd After Encryption:"+encryptionPasswd); Debug.Log ("Passwd After DeEncryption:"+encrytion.decipheringContent(encryptionPasswd,keyStr)); } } else { Debug.Log ("請輸入註冊信息"); } } }
/****************************** * 對數據庫操做的封裝 * @Author wuzhang * 2014/12/4 *****************************/ using UnityEngine; using System; using System.Data; using System.Collections; using MySql.Data.MySqlClient; using MySql.Data; using System.IO;
public class SqlAccess { public static MySqlConnection dbConnection; //若是隻是在本地的話,寫localhost就能夠。 // static string host = "localhost"; //若是是局域網,那麼寫上本機的局域網IP static string host = "127.0.0.1"; static string id = "root"; static string pwd = ""; static string database = "login"; public SqlAccess() { OpenSql(); // <-- 連接數據庫 } public static void OpenSql() { try { string connectionString = string.Format("Server = {0};port={4};Database = {1}; User ID = {2}; Password = {3};",host,database,id,pwd,"3306"); dbConnection = new MySqlConnection(connectionString); dbConnection.Open(); } catch (Exception e) { throw new Exception("服務器鏈接失敗,請從新檢查是否打開MySql服務。" + e.Message.ToString()); } }
// useless... public DataSet CreateTable (string name, string[] col, string[] colType) { if (col.Length != colType.Length) { throw new Exception ("columns.Length != colType.Length"); }
string query = "CREATE TABLE " + name + " (" + col[0] + " " + colType[0]; for (int i = 1; i < col.Length; ++i) { query += ", " + col[i] + " " + colType[i]; } query += ")";
return ExecuteQuery(query); }
// useless... public DataSet CreateTableAutoID (string name, string[] col, string[] colType) { if (col.Length != colType.Length) { throw new Exception ("columns.Length != colType.Length"); } string query = "CREATE TABLE " + name + " (" + col[0] + " " + colType[0] + " NOT NULL AUTO_INCREMENT"; for (int i = 1; i < col.Length; ++i) { query += ", " + col[i] + " " + colType[i]; } query += ", PRIMARY KEY ("+ col[0] +")" + ")"; Debug.Log(query); return ExecuteQuery(query); } //插入一條數據,包括全部,不適用自動累加ID。 public DataSet InsertInto (string tableName, string[] values) { string query = "INSERT INTO " + tableName + " VALUES (" + "'"+ values[0]+ "'"; for (int i = 1; i < values.Length; ++i) { query += ", " + "'"+values[i]+ "'"; } query += ")"; Debug.Log(query); return ExecuteQuery (query); } //插入部分ID public DataSet InsertInto (string tableName, string[] col,string[] values) { if (col.Length != values.Length) { throw new Exception ("columns.Length != colType.Length"); } string query = "INSERT INTO " + tableName + " (" + col[0]; for (int i = 1; i < col.Length; ++i) { query += ", "+col[i]; } query += ") VALUES (" + "'"+ values[0]+ "'"; for (int i = 1; i < values.Length; ++i) { query += ", " + "'"+values[i]+ "'"; } query += ")"; Debug.Log(query); return ExecuteQuery (query); } /// <summary> /// 返回表的查詢結果 /// </summary> /// <returns>The all.</returns> /// <param name="Name">Name.</param> public DataSet SelectAll(string Name) { string query ="select * from "+" "+Name; return ExecuteQuery (query); } /// <summary> /// 條件查找 /// </summary> /// <returns>The where.</returns> /// <param name="tableName">Table name.</param> /// <param name="items">Items.</param> /// <param name="col">Col.</param> /// <param name="operation">Operation.</param> /// <param name="values">Values.</param> public DataSet SelectWhere (string tableName, string[] items, string[] col, string[] operation, string[] values) { if (col.Length != operation.Length || operation.Length != values.Length) { throw new Exception ("col.Length != operation.Length != values.Length"); } string query = "SELECT " + items[0]; for (int i = 1; i < items.Length; ++i) { query += ", " + items[i]; } query += " FROM " + tableName + " WHERE " + col[0] + operation[0] + "'" + values[0] + "' "; for (int i = 1; i < col.Length; ++i) { query += " AND " + col[i] + operation[i] + "'" + values[0] + "' "; } return ExecuteQuery (query); } /// <summary> /// 更新表信息 /// </summary> /// <returns>The into.</returns> /// <param name="tableName">Table name.</param> /// <param name="cols">Cols.</param> /// <param name="colsvalues">Colsvalues.</param> /// <param name="selectkey">Selectkey.</param> /// <param name="selectvalue">Selectvalue.</param> public DataSet UpdateInto (string tableName, string []cols,string []colsvalues,string selectkey,string selectvalue) { string query = "UPDATE "+tableName+" SET "+cols[0]+" = "+colsvalues[0]; for (int i = 1; i < colsvalues.Length; ++i) { query += ", " +cols[i]+" ="+ colsvalues[i]; } query += " WHERE "+selectkey+" = "+selectvalue+" "; return ExecuteQuery (query); } /// <summary> /// 條件刪除 /// </summary> /// <param name="tableName">Table name.</param> /// <param name="cols">Cols.</param> /// <param name="colsvalues">Colsvalues.</param> public DataSet Delete(string tableName,string []cols,string []colsvalues) { string query = "DELETE FROM "+tableName + " WHERE " +cols[0] +" = " + colsvalues[0]; for (int i = 1; i < colsvalues.Length; ++i) { query += " or " +cols[i]+" = "+ colsvalues[i]; } Debug.Log(query); return ExecuteQuery (query); } /// <summary> /// 關閉數據庫 /// </summary> public void Close() { if(dbConnection != null) { dbConnection.Close(); dbConnection.Dispose(); dbConnection = null; } } public DataSet ExistOrNot(string sql) { if(dbConnection.State==ConnectionState.Open) { Debug.Log (sql); DataSet ds = new DataSet(); //表的集合 try { MySqlDataAdapter da = new MySqlDataAdapter(sql, dbConnection); da.Fill(ds); } catch (Exception ee) { throw new Exception("SQL:" + sql + "/n" + ee.Message.ToString()); } finally { } return ds; } return null; } /// <summary> /// 返回檢索結果 /// </summary> /// <returns>The query.</returns> /// <param name="sqlString">Sql string.</param> public static DataSet ExecuteQuery(string sqlString) { if(dbConnection.State==ConnectionState.Open) { DataSet ds = new DataSet(); //表的集合 try { MySqlDataAdapter da = new MySqlDataAdapter(sqlString, dbConnection); da.Fill(ds); } catch (Exception ee) { throw new Exception("SQL:" + sqlString + "/n" + ee.Message.ToString()); } finally { } return ds; } return null; } /// <summary> /// 讀取數據集 /// </summary> /// <param name="ds">Ds.</param> public void ReadDs(DataSet ds) { if(ds!=null) { DataTable user = ds.Tables[0]; foreach(DataRow row in user.Rows) { foreach(DataColumn colum in user.Columns) { Debug.Log (row[colum]); } } } } }
Ref: Amazon Cognitoreact
經過Cognito 用戶池或SAML社交身份提供商進行登陸。git
From: 利用AWS雲構建您的下一款Unity 3D遊戲,原文連接github
一個難題:移動開發者每每須要容許用戶以無縫化方式在不一樣設備之間往來遷移(包括智能手機、平板設備以及遊戲主機等),並在無需實施應用程序總體更新的前提下對遊戲自己的外觀與邏輯進行調整。sql
有鑑於此,AWS Mobile Development團隊近來推出了其AWS Mobile SDK for Unity的開發者預覽版。數據庫
你們如今能夠將AWS服務與Unity相結合以構建起跨平臺應用程序。api
該SDK當中包含對Amazon Cognito、Amazon DynamoDB以及Amazon S3的支持能力。安全
AWS Mobile SDK for Unity可以與Unity 4.0及其更早版本相兼容,同時支持免費與高級兩套版本。服務器
1)
你們還能夠利用Amazon Cognito以安全方式訪問本身的AWS資源,同時在不一樣設備之間實現應用程序內容的保存與同步。
DynamoDB是一款靈活性出色的NoSQL數據庫,可以在任意負載規模下提供出色的一致性與10毫秒之內之延遲水平。
DynamoDB幫助你們將遊戲所需之數據加以保存,並在不一樣用戶之間進行分享——例如積分排行榜以及共享資產清單。
3)
不過DynamoDB並非咱們的唯一選擇。當咱們的遊戲依賴於規模龐大且使用頻率極高的變動資產時,也能夠利用Amazon S3將這些文件保存在雲環境當中,然後在遊戲運行時從新進行數據獲取。
這種方式可以幫助你們對遊戲中的資產進行更新,同時又無需經過應用程序商店發佈完整的更新內容。
Ref: AWS Mobile SDK for Unity Documentation
1. aws提供了不少服務:
AWS 文檔 計算 Amazon EC2 Amazon Elastic Container Registry Amazon Elastic Container Service Amazon Lightsail Amazon VPC AWS Batch AWS Elastic Beanstalk AWS Lambda AWS Serverless Application Repository 存儲 Amazon S3 Amazon EBS Amazon EFS Amazon Glacier AWS Snowball AWS Storage Gateway 數據庫 Amazon RDS Amazon DynamoDB Amazon ElastiCache Amazon Redshift Amazon Neptune 遷移 AWS Application Discovery Service AWS Database Migration Service AWS Import/Export AWS Migration Hub AWS Server Migration Service AWS Schema Conversion Tool AWS Snowball 網絡和內容分發 Amazon VPC Amazon CloudFront Amazon Route 53 API Gateway AWS Direct Connect Elastic Load Balancing 開發人員工具 AWS CodeStar AWS CodeCommit AWS CodeBuild AWS CodeDeploy AWS CodePipeline AWS Cloud9 AWS X-Ray AWS 工具和開發工具包 管理工具 Amazon CloudWatch AWS Auto Scaling AWS CloudFormation AWS CloudTrail AWS Config AWS OpsWorks AWS Service Catalog AWS Systems Manager Trusted Advisor AWS Health AWS 管理控制檯 AWS 命令行界面 AWS Tools for Windows PowerShell 媒體服務 Amazon Elastic Transcoder AWS Elemental MediaConvert AWS Elemental MediaLive AWS Elemental MediaPackage AWS Elemental MediaStore AWS Elemental MediaTailor 機器學習 Amazon Sagemaker Amazon Comprehend AWS Deep Learning AMI Amazon Lex Amazon Polly Amazon Rekognition Amazon Machine Learning AWS 上的 Apache MXnet Amazon Translate Amazon Transcribe AWS DeepLens 分析 Amazon Athena Amazon CloudSearch AWS Data Pipeline Amazon Elasticsearch Service Amazon EMR AWS Glue Amazon Kinesis Amazon QuickSight Amazon Redshift 安全性、身份與合規性 Identity & Access Management AWS Artifact AWS Certificate Manager AWS CloudHSM Amazon Cognito AWS Directory Service Amazon GuardDuty Amazon Inspector AWS KMS Amazon Macie AWS Organizations AWS Shield AWS Single Sign-On AWS WAF 移動服務 AWS AppSync (預覽版) AWS Mobile Hub AWS Device Farm Amazon Mobile Analytics Amazon Pinpoint 適用於 Android 的 AWS 移動軟件開發工具包 適用於 iOS 的 AWS 移動軟件開發工具包 適用於 Unity 的 AWS 移動軟件開發工具包 適用於 Xamarin 的 AWS 移動軟件開發工具包 Amazon SNS AR 和 VR Amazon Sumerian (預覽) 應用程序集成 AWS Step Functions Amazon SWF Amazon SQS Amazon SNS Amazon MQ 客戶互動 Amazon Connect Amazon SES 企業生產力 Alexa for Business Amazon Chime Amazon WorkDocs Amazon WorkMail 桌面和應用程序流式處理 Amazon WorkSpaces Amazon WAM Amazon AppStream 2.0 物聯網 AWS IoT Core Amazon FreeRTOS AWS Greengrass AWS IoT Device Management 遊戲開發 Amazon Lumberyard (beta) Amazon GameLift 開發工具包和工具箱 適用於 C++ 的 AWS 開發工具包 適用於 Go 的 AWS 開發工具包 適用於 Java 的 AWS 開發工具包 適用於 JavaScript 的 AWS 開發工具包 適用於 .NET 的 AWS 開發工具包 適用於 PHP 的 AWS 開發工具包 適用於 Python 的 AWS 開發工具包 (Boto3) 適用於 Ruby 的 AWS 開發工具包 AWS Toolkit for Eclipse AWS Toolkit for Visual Studio 適用於 Visual Studio Team Services 的 AWS 工具 其餘軟件和服務 AWS 帳單和成本管理 AWS Marketplace AWS Support Alexa Top Sites Alexa Web Information Service Amazon Silk AWS GovCloud(美國) 通常引用 區域和終端節點 安全證書 ARN 與服務命名空間 服務限制 AWS 詞彙表 AWS 管理控制檯 資源組 標籤編輯器 資源組標記 API 資源 AWS 快速入門 AWS 白皮書 AWS 培訓和認證 AWS 案例研究 關於 Kindle 的 AWS 文檔 AWS 文檔存檔
2. 關於對前端(移動端提供的服務):
3. 使用 Amazon Cognito Identity,
4. Amazon Cognito 開發人員指南 (細節) --> Go to link.
讓您輕鬆地爲移動和 Web 應用程序添加用戶註冊信息和登陸信息,並管理相關權限。
多重驗證 (MFA) 經過增長身份驗證方法而不是單靠用戶名 (或別名) 和密碼來提升應用程序的安全性。
找密碼用。
【理解爲具備某種權限的臨時用戶】
IAM 角色 相似於用戶,由於它是一個 AWS 實體,該實體具備肯定其在 AWS 中可執行和不可執行的操做的權限策略。
可是,角色旨在讓須要它的任何人代入,而不是惟一地與某我的員關聯。
此外,角色沒有關聯的標準長期憑證 (密碼或訪問密鑰)。相反,若是用戶擔任某個角色,則會動態建立臨時安全憑證併爲用戶提供該憑證。 // <----
您可使用角色向一般無權訪問您的 AWS 資源的用戶、應用程序或服務提供訪問權限。【像極了Linux權限管理】
例如,您可能須要向您 AWS 帳戶中的用戶授予對他們一般不擁有的資源的訪問權限,
或是向一個 AWS 帳戶的用戶授予對另外一個帳戶中的資源的訪問權限。
或者,您可能須要容許移動應用程序使用 AWS 資源,可是不但願將 AWS 密鑰嵌入在應用程序中 (在其中難以輪換密鑰,並且用戶可能提取它們)。
有時,您須要向已經具備在 AWS 外部 (例如,在您的公司目錄中) 定義的身份的用戶提供對 AWS 的訪問權限。或者,您可能須要向第三方授予對您帳戶的訪問權限,使他們能夠對您的資源執行審覈。
對於這些狀況,可以使用 IAM 角色委託對 AWS 資源的訪問權限。本節介紹各類角色和它們的不一樣使用方式,什麼時候及如何選擇方法,如何建立、管理、切換到 (或擔任) 和刪除角色。
注意:若是配置了 SMS 角色,則不能禁用 MFA!
您可使用 AWS Lambda 函數進行高級自定義設置。
若是您要自定義工做流和用戶體驗,可選擇 AWS Lambda 函數來觸發不一樣的事件。
導入對應的unitypackage。
可見,aws提供了一種更加便捷的方式,將用戶管理單獨採起aws的方案。
統一在一篇文章。
上接:[Unity3D] Access to DB or AWS
一些問題:Cognito User Pool vs Identity Pool
視頻教學:Weekend Hacks: Playing around with AWS Unity SDK; aws-sdk-unity-samples
實踐教學:AWS Cognito Sync in Unity
博客教學:Sign Up and Confirm With Amazon Cognito User Pools Using C#
示例代碼:awslabs/aws-cognito-dot-net-desktop-app; Code Walkthrough-DotNet
接口文檔:AWS SDK for .NET Version 3 API Reference
Download project: ChessGame
ChessGameScenes中放入:CognitoSyncManagerSample.unity
ChessGameScripts中放入:CognitoSyncManagerSample.cs
Create new identity pool.
Sign in to the Amazon Cognito console, choose Manage Federated Identities, and then choose Create new identity pool.