本文整理汇总了C#中Connection.ReadNextMsgAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.ReadNextMsgAsync方法的具体用法?C# Connection.ReadNextMsgAsync怎么用?C# Connection.ReadNextMsgAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection.ReadNextMsgAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
public static async Task<Account> Authenticate(Connection con)
{
await con.SendAsync("Please enter your username: (hit enter to register a new account)");
var username = await con.ReadNextMsgAsync();
Account account;
if (username == "") {
account = await Registrar.Register(con);;
} else {
var accounttask = Account.FromUsername(username);
await con.SendAsync("Enter password: ");
var pw = await con.ReadNextMsgAsync();
account = await accounttask;
var utf8 = new UTF8Encoding();
if (account.GetPasswordHash() != PasswordSecurity.GenerateSaltedHash(utf8.GetBytes(pw), account.GetSalt())) {
await con.SendAsync("Wrong password");
return await Authenticate(con);
}
}
return account;
}
示例2: ReceiveValidPassword
private static async Task<string> ReceiveValidPassword(Connection con)
{
await con.SendAsync("Enter your desired password: ");
var pw1 = await con.ReadNextMsgAsync();
await con.SendAsync("Enter it again: ");
var pw2 = await con.ReadNextMsgAsync();
if (pw1 != pw2) {
await con.SendAsync("Passwords don't match, try again ");
return await ReceiveValidPassword(con);
}
return pw1;
}
示例3: ReceiveValidUsername
private static async Task<string> ReceiveValidUsername(Connection con)
{
await con.SendAsync("Please enter your desired username (a-Z, 0-9, _): ");
var username = await con.ReadNextMsgAsync();
if (await Account.IsUsernameTaken(username)) {
await con.SendAsync("That name is already taken, please choose another one");
return await ReceiveValidUsername(con);
}
return username;
}