public bool Authenticate(AuthenticationPoint point, Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.Unicode); BinaryWriter writer = new BinaryWriter(stream, Encoding.Unicode); if (point == AuthenticationPoint.Client) { long rv = reader.ReadInt64(); // Send the password, writer.Write(rv); short sz = (short)Password.Length; writer.Write(sz); for (int i = 0; i < sz; ++i) { writer.Write(Password[i]); } writer.Flush(); return(true); } else { // Write a random long and see if it gets pinged back from the client, byte[] bytes = new byte[8]; random.NextBytes(bytes); long rv = BitConverter.ToInt64(bytes, 0); writer.Write(rv); writer.Flush(); long feedback = reader.ReadInt64(); if (rv != feedback) { // Silently close if the value not returned, writer.Close(); reader.Close(); return(false); } // Read the password string from the stream, short sz = reader.ReadInt16(); StringBuilder sb = new StringBuilder(sz); for (int i = 0; i < sz; ++i) { sb.Append(reader.ReadChar()); } string passwordCode = sb.ToString(); return(passwordCode.Equals(Password)); } }
public bool Authenticate(AuthenticationPoint point, Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.Unicode); BinaryWriter writer = new BinaryWriter(stream, Encoding.Unicode); if (point == AuthenticationPoint.Client) { long rv = reader.ReadInt64(); // Send the password, writer.Write(rv); short sz = (short)Password.Length; writer.Write(sz); for (int i = 0; i < sz; ++i) { writer.Write(Password[i]); } writer.Flush(); return true; } else { // Write a random long and see if it gets pinged back from the client, byte[] bytes = new byte[8]; random.NextBytes(bytes); long rv = BitConverter.ToInt64(bytes, 0); writer.Write(rv); writer.Flush(); long feedback = reader.ReadInt64(); if (rv != feedback) { // Silently close if the value not returned, writer.Close(); reader.Close(); return false; } // Read the password string from the stream, short sz = reader.ReadInt16(); StringBuilder sb = new StringBuilder(sz); for (int i = 0; i < sz; ++i) sb.Append(reader.ReadChar()); string passwordCode = sb.ToString(); return passwordCode.Equals(Password); } }
public AuthResult Authenticate(AuthenticationPoint authPoint, AuthRequest authRequest) { throw new NotImplementedException(); }
public bool Authenticate(AuthenticationPoint point, Stream stream) { return true; }
public bool Authenticate(AuthenticationPoint point, Stream stream) { return(true); }