Application connecting to database server

I’m working on an application which requires user credentials and so on. So a database is required on the backend.

What is the best practice to connect to a database without hardcoding your password into it? The program could be reverse engineered and one might get the password which is something we obviously don’t want.

1

I just went though this myself. Assuming you’re using SQL Server, I actually created user accounts on the database server for every user (you can do this from t-sql). I have one general user account that I can use to first verify that I can make a connection, and select from a Version table that makes sure the version of the software running matches the database schema version.

Users who have the ability to add/remove users in the application also need to have rights to administrate users on the database server. This is actually a problem since the users are defined at the database server level, not at the database level. That means someone with the ability to add/remove database server users could potentially create a new user that could access another database. For this reason, I suggest running a separate instance of the database server for this.

There are other ways to go about it:

  • If your users login to Windows with unique accounts, you can use integrated security where they just authenticate with the Windows credentials. Ideal if it works for you (we had some shared computers, so it didn’t).
  • You can have a common user and hard-code the credentials in the connection string, but only give that user access to stored procedures, not tables. Then in the stored procedures you have to pass login credentials every time, and the stored proc does the authentication. This has the advantage of allowing more granular security (you can limit what rows they can get back, so for instance, they wouldn’t be able to see another user’s timesheet records, but they could see their own).
  • If you need only rudimentary protection of some data, just have two users: NormalUser and AdministratorUser. Only store the NormalUser’s password in the connection string. When you need to do something that requires administrator level permissions, have them enter the AdministratorUser’s password, and open a new connection.
  • Put the database into local-only mode (no remote connections) and create a web service that runs on that machine and acts as your data access layer. This will let you do really advanced security (gives you full control over what a user can see) and it means the rest of your application basically sees the data as business objects rather than rows and columns. The web service, obviously, needs to handle the authentication.

Put your credentials information in the <connectionString /> on the app.config file. Then, proceed to encrypt the <connectionStrings /> section.

See the following article for more information: Encrypting Passwords in a .NET app.config File

2

The best practice is to give each user their own account on the database, and to set permissions on that account to restrict their access as you see fit.

The user’s credentials go into a configuration file for the application.

Can you use integrated authentication? For example, in SQL Server 2008 R2, the following connection string accesses the local master database using Windows credentials.

Data Source=localhost;Initial Catalog=master;Trusted_Connection=true

And I would never recommend creating SQL users for an application. You are now giving direct database access to your users, who should always be using the application (unless you explicitly allow them direct access). Additionally you are restricted by what tools SQL offers you for authentication. A common problem is per-row access, your application can do the filtering pretty easily, but creating stored procedures to duplicate it is non-trivial.

To be fair though, you do need to worry about escalation of rights attacks when using a proxied account.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật