Beispiel #1
0
        public bool IsInRole(string role)
        {
            MyPrincipal principal = null;

            if (Thread.CurrentPrincipal.GetType().Equals(typeof(MyPrincipal)))
            {
                principal = (MyPrincipal)Thread.CurrentPrincipal;
            }
            UserStore store = new UserStore();
            Task <IList <string> > roles = store.GetRolesAsync(principal.MyIdentity);

            for (int i = 0; i < roles.Result.Count; i++)
            {
                if (roles.Result[i].ToUpper() == role.ToUpper())
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        public static async Task <MyPrincipal> BuildNewIdentity(string username, string dipartimento, string password, string type)
        {
            UserStore   store     = new UserStore();
            RoleStore   roleStore = new RoleStore();
            MyPrincipal mp        = null;
            //LoginResp r = store.Authenticate(username, dipartimento, password);
            int    iduser       = 0;
            string passwordHash = await store.GetPasswordHashAsync(username, ref iduser);

            string digitPasswordSHA = MySecurityProvider.PlainToSHA256(password);

            if (digitPasswordSHA == passwordHash)
            {
                MyIdentity id = new MyIdentity(username, dipartimento, password, type);
                id.Id = iduser.ToString();
                mp    = new MyPrincipal(id, null);
            }
            else
            {
                MyIdentity id = new MyIdentity(username, dipartimento);
                mp = new MyPrincipal(id, null);
            }
            return(await Task.FromResult(mp));
        }