O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a very simple user database

The user database will only contain our one user. We leave it to the reader to create a more dynamic user database:

private IUserSource users = new Users(); 
 
public class Users : IUserSource 
{ 
   public bool TryGetUser(string UserName, out IUser User) 
   { 
          if (UserName == "MIoT") 
                 User = new User(); 
          else 
                 User = null; 
 
          return User != null; 
   } 
} 

We also define our salted hash function as follows, using the unique device identity as the salt:

private string CalcHash(string Password) 
{ 
   return Waher.Security.Hashes.ComputeSHA256HashString( 
          Encoding.UTF8.GetBytes(Password + ":" + this.deviceId)); 
} 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required