ibrahimlita 0 Newbie Poster
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Windows.Forms;

        namespace DBCsharp
        {
            class authentiction
            {
                public static int logged_user_id=0;
                public static bool CanAddUser = false;
                public static bool CanDeleteUser = false;


                public static TaregData db = new TaregData();
                public static bool log_user(string username,string password) {

                    var user = (from a in db.Users 
                                where a.username == username
                                select a).DefaultIfEmpty();
                    if (user.First() != null)
                    {
                        var user_pass = (from a in db.Users
                                         where a.username == username && a.Pass  == password
                                         select a).DefaultIfEmpty();
                        if (user_pass.First() != null)
                        {
                            logged_user_id = user_pass.First().user_id;

                            var p = from a in db.user_privs 
                                    where a.user_id == logged_user_id
                                    select a;
                            foreach(var t in p){

                                switch (t.priv_id) { 
                                    case 1:
                                        CanAddUser = true;
                                        break;
                                    case 2:
                                        CanDeleteUser = true;
                                        break;
                                    default:
                                        break; 
                                }

                            }


                            return true;

                        }
                        else { return false; }


                    }
                    else
                    {
                        return false;
                    }




                }
            }
        }


        class authentiction
        {
            public static int logged_user_id=0;
            public static bool CanAddUser = false;
            public static bool CanDeleteUser = false;


            public static TaregData db = new TaregData();
            public static bool log_user(string username,string password) {

                var user = (from a in db.Users 
                            where a.username == username
                            select a).DefaultIfEmpty();
                if (user.First() != null)
                {
                    var user_pass = (from a in db.Users
                                     where a.username == username && a.Pass  == password
                                     select a).DefaultIfEmpty();
                    if (user_pass.First() != null)
                    {
                        logged_user_id = user_pass.First().user_id;

                        var p = from a in db.user_privs 
                                where a.user_id == logged_user_id
                                select a;
                        foreach(var t in p){

                            switch (t.priv_id) { 
                                case 1:
                                    CanAddUser = true;
                                    break;
                                case 2:
                                    CanDeleteUser = true;
                                    break;
                                default:
                                    break; 
                            }

                        }


                        return true;

                    }
                    else { return false; }


                }
                else
                {
                    return false;
                }




            }
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.