密码加密保存
服务器地址可以通过ini修改,默认写入程序
This commit is contained in:
parent
b728584628
commit
2f26de2196
@ -15,6 +15,7 @@ using Plane.Communication;
|
|||||||
using Plane.Util;
|
using Plane.Util;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Plane.Windows.Messages;
|
using Plane.Windows.Messages;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Plane.FormationCreator.Formation
|
namespace Plane.FormationCreator.Formation
|
||||||
{
|
{
|
||||||
@ -34,7 +35,7 @@ namespace Plane.FormationCreator.Formation
|
|||||||
public int AddCopter(ICopter entityObject,bool sortbyid=true)
|
public int AddCopter(ICopter entityObject,bool sortbyid=true)
|
||||||
{
|
{
|
||||||
////给第三方时候限制数量和时间用
|
////给第三方时候限制数量和时间用
|
||||||
DateTime dateTime2019 = DateTime.Parse("2020-03-01");
|
DateTime dateTime2019 = DateTime.Parse("2020-06-01");
|
||||||
|
|
||||||
//新增飞机区域限制:内蒙
|
//新增飞机区域限制:内蒙
|
||||||
// if (entityObject.Latitude < 37.4307185218 || entityObject.Latitude > 45.6754821756
|
// if (entityObject.Latitude < 37.4307185218 || entityObject.Latitude > 45.6754821756
|
||||||
@ -128,10 +129,10 @@ namespace Plane.FormationCreator.Formation
|
|||||||
|
|
||||||
public class CopterManager : ObservableObject
|
public class CopterManager : ObservableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const string LoginPage = "checkforapp.php";
|
||||||
const string supername = "admin";
|
const string supername = "admin";
|
||||||
const string superpass = "fxmf0622";
|
const string superpass = "fxmf0622";
|
||||||
//服务器地址
|
|
||||||
const string strUrlPre = "http://111.229.174.37:81/login/checkforapp.php";
|
|
||||||
//用户级别
|
//用户级别
|
||||||
const int LEVEL_NORMAL = 1;
|
const int LEVEL_NORMAL = 1;
|
||||||
const int LEVEL_ADMIN = 0;
|
const int LEVEL_ADMIN = 0;
|
||||||
@ -267,7 +268,7 @@ namespace Plane.FormationCreator.Formation
|
|||||||
{
|
{
|
||||||
// 发送请求
|
// 发送请求
|
||||||
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
||||||
sbUrl.Append(strUrlPre);
|
sbUrl.Append(VersionControl.ServerURL+ LoginPage);
|
||||||
sbUrl.Append("?");
|
sbUrl.Append("?");
|
||||||
sbUrl.Append("username=" + _UserName);
|
sbUrl.Append("username=" + _UserName);
|
||||||
sbUrl.Append("&type=Active");
|
sbUrl.Append("&type=Active");
|
||||||
@ -280,13 +281,12 @@ namespace Plane.FormationCreator.Formation
|
|||||||
{
|
{
|
||||||
// 发送请求
|
// 发送请求
|
||||||
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
||||||
sbUrl.Append(strUrlPre);
|
sbUrl.Append(VersionControl.ServerURL + LoginPage);
|
||||||
sbUrl.Append("?");
|
sbUrl.Append("?");
|
||||||
sbUrl.Append("username=" + _UserName);
|
sbUrl.Append("username=" + _UserName);
|
||||||
|
|
||||||
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
|
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
|
||||||
sbUrl.Append("&type=Logout");
|
sbUrl.Append("&type=Logout");
|
||||||
|
sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
String strUrl = sbUrl.ToString();
|
String strUrl = sbUrl.ToString();
|
||||||
string errorstr;
|
string errorstr;
|
||||||
new AsynDataUtils().AsynGetData(strUrl, null, out errorstr);
|
new AsynDataUtils().AsynGetData(strUrl, null, out errorstr);
|
||||||
@ -313,7 +313,7 @@ namespace Plane.FormationCreator.Formation
|
|||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
||||||
sbUrl.Append(strUrlPre);
|
sbUrl.Append(VersionControl.ServerURL + LoginPage);
|
||||||
sbUrl.Append("?");
|
sbUrl.Append("?");
|
||||||
sbUrl.Append("username=" + _UserName);
|
sbUrl.Append("username=" + _UserName);
|
||||||
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
|
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
|
||||||
@ -322,7 +322,7 @@ namespace Plane.FormationCreator.Formation
|
|||||||
sbUrl.Append("&orgLng="+ OriginLng.ToString());
|
sbUrl.Append("&orgLng="+ OriginLng.ToString());
|
||||||
sbUrl.Append("&orgLat="+ OriginLat.ToString());
|
sbUrl.Append("&orgLat="+ OriginLat.ToString());
|
||||||
sbUrl.Append("&coptercount=" + Copters.Count().ToString());
|
sbUrl.Append("&coptercount=" + Copters.Count().ToString());
|
||||||
|
sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
String strUrl = sbUrl.ToString();
|
String strUrl = sbUrl.ToString();
|
||||||
string errorstr;
|
string errorstr;
|
||||||
new AsynDataUtils().AsynGetData(strUrl, null, out errorstr);
|
new AsynDataUtils().AsynGetData(strUrl, null, out errorstr);
|
||||||
@ -393,6 +393,10 @@ namespace Plane.FormationCreator.Formation
|
|||||||
{
|
{
|
||||||
NetLogout();
|
NetLogout();
|
||||||
Alert.Show("该账号已在其他地方登录!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
Alert.Show("该账号已在其他地方登录!", "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
NetLogout();
|
||||||
|
Alert.Show("登录失败:"+ data, "登录提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void NetLogoin(string username,string password,bool savepassword)
|
public void NetLogoin(string username,string password,bool savepassword)
|
||||||
@ -410,10 +414,12 @@ namespace Plane.FormationCreator.Formation
|
|||||||
tempSavePassword = savepassword;
|
tempSavePassword = savepassword;
|
||||||
// 发送请求
|
// 发送请求
|
||||||
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
||||||
sbUrl.Append(strUrlPre);
|
sbUrl.Append(VersionControl.ServerURL + LoginPage);
|
||||||
sbUrl.Append("?");
|
sbUrl.Append("?");
|
||||||
sbUrl.Append("username=" + username);
|
sbUrl.Append("username=" + username);
|
||||||
sbUrl.Append("&" + "password=" + password);
|
sbUrl.Append("&" + "password=" + password);
|
||||||
|
sbUrl.Append("&type=Login");
|
||||||
|
sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
|
sbUrl.Append("&" + "clientname=" + System.Net.Dns.GetHostName());
|
||||||
String strUrl = sbUrl.ToString();
|
String strUrl = sbUrl.ToString();
|
||||||
string errorstr;
|
string errorstr;
|
||||||
@ -463,12 +469,13 @@ namespace Plane.FormationCreator.Formation
|
|||||||
tempPassword = oldpassword;
|
tempPassword = oldpassword;
|
||||||
// 发送请求
|
// 发送请求
|
||||||
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
StringBuilder sbUrl = new StringBuilder(); // 请求URL内容
|
||||||
sbUrl.Append(strUrlPre);
|
sbUrl.Append(VersionControl.ServerURL + LoginPage);
|
||||||
sbUrl.Append("?");
|
sbUrl.Append("?");
|
||||||
sbUrl.Append("username=" + username);
|
sbUrl.Append("username=" + username);
|
||||||
sbUrl.Append("&password=" + oldpassword);
|
sbUrl.Append("&password=" + oldpassword);
|
||||||
sbUrl.Append("&clientname=" + System.Net.Dns.GetHostName());
|
sbUrl.Append("&clientname=" + System.Net.Dns.GetHostName());
|
||||||
sbUrl.Append("&type=Chpassword");
|
sbUrl.Append("&type=Chpassword");
|
||||||
|
sbUrl.Append("&ver=" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
sbUrl.Append("&newpassword=" + newpassword);
|
sbUrl.Append("&newpassword=" + newpassword);
|
||||||
String strUrl = sbUrl.ToString();
|
String strUrl = sbUrl.ToString();
|
||||||
string errorstr;
|
string errorstr;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using Plane.Windows.IniHelper;
|
using Plane.Windows.IniHelper;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +11,7 @@ namespace Plane.FormationCreator.Util
|
|||||||
{
|
{
|
||||||
public static class VersionControl
|
public static class VersionControl
|
||||||
{
|
{
|
||||||
|
private static string DefaultServrURL= "http://111.229.174.37:81/login/";
|
||||||
public static int Version = 0;
|
public static int Version = 0;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否是完整版本 仅在Version = 255时为完整版本
|
/// 是否是完整版本 仅在Version = 255时为完整版本
|
||||||
@ -24,6 +27,8 @@ namespace Plane.FormationCreator.Util
|
|||||||
public static string Password = "";
|
public static string Password = "";
|
||||||
public static bool IssavePassword = false;
|
public static bool IssavePassword = false;
|
||||||
|
|
||||||
|
public static string ServerURL = "";
|
||||||
|
|
||||||
public static void SetUserLever(int vuserlever)
|
public static void SetUserLever(int vuserlever)
|
||||||
{
|
{
|
||||||
if (vuserlever==0)
|
if (vuserlever==0)
|
||||||
@ -58,7 +63,7 @@ namespace Plane.FormationCreator.Util
|
|||||||
if (readvalue != "")
|
if (readvalue != "")
|
||||||
Username = readvalue;
|
Username = readvalue;
|
||||||
|
|
||||||
readvalue = iniFiles.IniReadvalue("Login", "Password");
|
readvalue = Decrypt(iniFiles.IniReadvalue("Login", "Password"));
|
||||||
if (readvalue != "")
|
if (readvalue != "")
|
||||||
Password = readvalue;
|
Password = readvalue;
|
||||||
|
|
||||||
@ -67,6 +72,19 @@ namespace Plane.FormationCreator.Util
|
|||||||
if (readvalue != "" && bool.TryParse(readvalue, out boolTemp))
|
if (readvalue != "" && bool.TryParse(readvalue, out boolTemp))
|
||||||
IssavePassword = bool.Parse(readvalue);
|
IssavePassword = bool.Parse(readvalue);
|
||||||
|
|
||||||
|
readvalue = iniFiles.IniReadvalue("Default", "Server");
|
||||||
|
if (readvalue != "")
|
||||||
|
ServerURL = readvalue;
|
||||||
|
else
|
||||||
|
ServerURL = DefaultServrURL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveLogininfoToIni(string username,string password,bool issavepassword)
|
public static void SaveLogininfoToIni(string username,string password,bool issavepassword)
|
||||||
@ -77,7 +95,7 @@ namespace Plane.FormationCreator.Util
|
|||||||
IniFiles iniFiles = new IniFiles();
|
IniFiles iniFiles = new IniFiles();
|
||||||
iniFiles.IniWritevalue("Login", "Username", username);
|
iniFiles.IniWritevalue("Login", "Username", username);
|
||||||
if (issavepassword)
|
if (issavepassword)
|
||||||
iniFiles.IniWritevalue("Login", "Password", password);
|
iniFiles.IniWritevalue("Login", "Password", Encrypt(password));
|
||||||
else
|
else
|
||||||
iniFiles.IniWritevalue("Login", "Password", "");
|
iniFiles.IniWritevalue("Login", "Password", "");
|
||||||
|
|
||||||
@ -87,7 +105,62 @@ namespace Plane.FormationCreator.Util
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string encryptKey = "fxmf";//字符串加密密钥(注意:密钥只能是4位)
|
||||||
|
|
||||||
|
private static string Encrypt(string str)
|
||||||
|
{//加密字符串
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] key = Encoding.Unicode.GetBytes(encryptKey);//密钥
|
||||||
|
byte[] data = Encoding.Unicode.GetBytes(str);//待加密字符串
|
||||||
|
|
||||||
|
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();//加密、解密对象
|
||||||
|
MemoryStream MStream = new MemoryStream();//内存流对象
|
||||||
|
|
||||||
|
//用内存流实例化加密流对象
|
||||||
|
CryptoStream CStream = new CryptoStream(MStream, descsp.CreateEncryptor(key, key), CryptoStreamMode.Write);
|
||||||
|
CStream.Write(data, 0, data.Length);//向加密流中写入数据
|
||||||
|
CStream.FlushFinalBlock();//将数据压入基础流
|
||||||
|
byte[] temp = MStream.ToArray();//从内存流中获取字节序列
|
||||||
|
CStream.Close();//关闭加密流
|
||||||
|
MStream.Close();//关闭内存流
|
||||||
|
|
||||||
|
return Convert.ToBase64String(temp);//返回加密后的字符串
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static string Decrypt(string str)
|
||||||
|
{//解密字符串
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] key = Encoding.Unicode.GetBytes(encryptKey);//密钥
|
||||||
|
byte[] data = Convert.FromBase64String(str);//待解密字符串
|
||||||
|
|
||||||
|
DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();//加密、解密对象
|
||||||
|
MemoryStream MStream = new MemoryStream();//内存流对象
|
||||||
|
|
||||||
|
//用内存流实例化解密流对象
|
||||||
|
CryptoStream CStream = new CryptoStream(MStream, descsp.CreateDecryptor(key, key), CryptoStreamMode.Write);
|
||||||
|
CStream.Write(data, 0, data.Length);//向加密流中写入数据
|
||||||
|
CStream.FlushFinalBlock();//将数据压入基础流
|
||||||
|
byte[] temp = MStream.ToArray();//从内存流中获取字节序列
|
||||||
|
CStream.Close();//关闭加密流
|
||||||
|
MStream.Close();//关闭内存流
|
||||||
|
|
||||||
|
return Encoding.Unicode.GetString(temp);//返回解密后的字符串
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user