diff --git a/.github/workflows/semgrep.yml b/.github/workflows/semgrep.yml new file mode 100644 index 00000000..b7f18722 --- /dev/null +++ b/.github/workflows/semgrep.yml @@ -0,0 +1,40 @@ +# Name of this GitHub Actions workflow. +name: Semgrep + +on: + # Scan changed files in PRs (diff-aware scanning): + pull_request: {} + # Scan on-demand through GitHub Actions interface: + workflow_dispatch: {} + # Scan mainline branches and report all findings: + push: + branches: ["master", "main"] + # Schedule the CI job (this method uses cron syntax): + schedule: + - cron: '20 17 * * *' # Sets Semgrep to scan every day at 17:20 UTC. + # It is recommended to change the schedule to a random time. + +jobs: + semgrep: + # User definable name of this GitHub Actions job. + name: semgrep/ci + # If you are self-hosting, change the following `runs-on` value: + runs-on: ubuntu-latest + + container: + # A Docker image with Semgrep installed. Do not change this. + image: returntocorp/semgrep + + # Skip any PR created by dependabot to avoid permission issues: + if: (github.actor != 'dependabot[bot]') + + steps: + # Fetch project source with GitHub Actions Checkout. + - uses: actions/checkout@v3 + # Run the "semgrep ci" command on the command line of the docker image. + - run: semgrep ci + env: + # Connect to Semgrep Cloud Platform through your SEMGREP_APP_TOKEN. + # Generate a token from Semgrep Cloud Platform > Settings + # and add it to your GitHub secrets. + SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} diff --git a/NewFileAdded/AdminDetailsServiceImpl.java b/NewFileAdded/AdminDetailsServiceImpl.java new file mode 100644 index 00000000..c34b5d17 --- /dev/null +++ b/NewFileAdded/AdminDetailsServiceImpl.java @@ -0,0 +1,39 @@ +package com.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import com.model.Admin; +import com.model.User; +import com.repository.AdminRepository; +import com.repository.UserRepository; + +@Service +public class AdminDetailsServiceImpl implements UserDetailsService{ + + @Autowired + private AdminRepository adminRepository; + + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + + + //fetching user from + + Admin admin = adminRepository.getAdminByName(username); + + if(admin == null) + { + throw new UsernameNotFoundException("Could not found admin !!"); + + } + CustomAdminDetails customAdminDetails = new CustomAdminDetails(admin); + + return customAdminDetails; + } + +} diff --git a/NewFileAdded/Client.java b/NewFileAdded/Client.java new file mode 100644 index 00000000..52249447 --- /dev/null +++ b/NewFileAdded/Client.java @@ -0,0 +1,90 @@ +import java.net.Socket; + +import java.net.*; +import java.io.*; + +public class Client { + +Socket socket; + +BufferedReader br; +PrintWriter out; + + +public Client(){ + + + try{ + System.out.println("Sending request to server"); + socket=new Socket("127.0.0.1",7777); + System.out.println("Connection done!!"); + + br = new BufferedReader(new InputStreamReader(socket.getInputStream())); + + out = new PrintWriter(socket.getOutputStream()); + + startReading(); + startWriting(); + +} + catch(Exception e){} +} + +public void startReading(){ + Runnable r1=()->{ + System.out.println("reader started..."); + + try{ + while(true){ + + String msg = br.readLine(); + if(msg.equals("EXIT")){System.out.println("Server terminated the chatting!!"); + socket.close(); + break;} + + System.out.println("Server : "+msg); + + + } + }catch(Exception e){System.out.print("----Connection is Closed----");} + }; + + new Thread(r1).start(); + } + + + + public void startWriting(){ + Runnable r2=()->{ + System.out.println("Writer started..."); + + try{ + while(!socket.isClosed()){ + + BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); + + String content=br1.readLine(); + out.println(content); + out.flush(); + + if(content.equals("EXIT")){ + socket.close(); + break; + } + + System.out.print("----Connection is Closed----"); + } + }catch(Exception e){}; + }; + + new Thread(r2).start(); + } + + + + public static void main(String[] args){ + + System.out.println("this is client..."); + new Client(); + } +} diff --git a/NewFileAdded/CustomAdminDetails.java b/NewFileAdded/CustomAdminDetails.java new file mode 100644 index 00000000..74ec3c28 --- /dev/null +++ b/NewFileAdded/CustomAdminDetails.java @@ -0,0 +1,79 @@ +package com.config; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import com.model.Admin; +import com.model.Role; +import com.model.User; + + + +public class CustomAdminDetails implements UserDetails { + + + private Admin adm; + + + public CustomAdminDetails(Admin adm) { + this.adm = adm; + } + + @Override + public Collection getAuthorities() { + + List authorities = new ArrayList<>(); + + Iterator itr = adm.getRoles().iterator(); + while(itr.hasNext()) + { + authorities.add(new SimpleGrantedAuthority(itr.next().getName())); + } + + return authorities; + } + + @Override + public String getPassword() { + + return adm.getPassword(); + } + + @Override + public String getUsername() { + + return adm.getName(); + } + + @Override + public boolean isAccountNonExpired() { + + return true; + } + + @Override + public boolean isAccountNonLocked() { + + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + + return true; + } + + @Override + public boolean isEnabled() { + + return true; + } + +} diff --git a/NewFileAdded/CustomSuccessHandler.java b/NewFileAdded/CustomSuccessHandler.java new file mode 100644 index 00000000..7c943f2a --- /dev/null +++ b/NewFileAdded/CustomSuccessHandler.java @@ -0,0 +1,46 @@ +package com.config; + +import java.io.IOException; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; + + +@Configuration +public class CustomSuccessHandler implements AuthenticationSuccessHandler{ + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, + Authentication authentication) throws IOException, ServletException { + // TODO Auto-generated method stub + + Set roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); + + if(roles.contains("ROLE_ADMIN")) + { + response.sendRedirect("/admin/"); + } + else if(roles.contains("ROLE_USER")) + { + response.sendRedirect("/user/"); + } + else + { + response.sendRedirect("/signin"); + } + + } + + + + + + +} diff --git a/NewFileAdded/CustomUserDetails.java b/NewFileAdded/CustomUserDetails.java new file mode 100644 index 00000000..162b17c4 --- /dev/null +++ b/NewFileAdded/CustomUserDetails.java @@ -0,0 +1,78 @@ +package com.config; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import com.model.Role; +import com.model.User; + + + +public class CustomUserDetails implements UserDetails { + + + private User user; + + + public CustomUserDetails(User user) { + this.user = user; + } + + @Override + public Collection getAuthorities() { + + List authorities = new ArrayList<>(); + + Iterator itr = user.getRoles().iterator(); + while(itr.hasNext()) + { + authorities.add(new SimpleGrantedAuthority(itr.next().getName())); + } + + return authorities; + } + + @Override + public String getPassword() { + + return user.getPassword(); + } + + @Override + public String getUsername() { + + return user.getEmail(); + } + + @Override + public boolean isAccountNonExpired() { + + return true; + } + + @Override + public boolean isAccountNonLocked() { + + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + + return true; + } + + @Override + public boolean isEnabled() { + + return true; + } + +} diff --git a/NewFileAdded/MyConfig.java b/NewFileAdded/MyConfig.java new file mode 100644 index 00000000..d706f48d --- /dev/null +++ b/NewFileAdded/MyConfig.java @@ -0,0 +1,114 @@ +package com.config; + + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.NoOpPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; + +@Configuration +@EnableWebSecurity +public class MyConfig extends WebSecurityConfigurerAdapter{ + + @Autowired + private AuthenticationSuccessHandler customSuccessHandler; + + @Autowired + private AdminDetailsServiceImpl adminDSImpl; + + @Autowired + private UserDetailsServiceImpl userDSImpl; + + @Bean + public UserDetailsService getAdminDetailsServicie() + { + + + return adminDSImpl; + + + } + + @Bean + public UserDetailsService getUserDetailsServicie() + { + + + return userDSImpl; + + + } + + + @Bean + public PasswordEncoder passwordEncoder() + { + return NoOpPasswordEncoder.getInstance(); + } + + @Bean + public DaoAuthenticationProvider authenticationProvider() + { + DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); + daoAuthenticationProvider.setUserDetailsService(this.getUserDetailsServicie()); + daoAuthenticationProvider.setPasswordEncoder(passwordEncoder()); + + return daoAuthenticationProvider; + + } + + @Bean + public DaoAuthenticationProvider authenticationProvider2() + { + DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); + daoAuthenticationProvider.setUserDetailsService(this.getAdminDetailsServicie()); + daoAuthenticationProvider.setPasswordEncoder(passwordEncoder()); + + return daoAuthenticationProvider; + + } + + + ///configure method... + + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + + auth.authenticationProvider(authenticationProvider()); + auth.authenticationProvider(authenticationProvider2()); + + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + + http + .authorizeRequests() + .antMatchers("/admin/**").hasRole("ADMIN") + .antMatchers("/user/**").hasRole("USER") + .antMatchers("/**").permitAll() + .and().formLogin().loginPage("/signin") + .loginProcessingUrl("/dologin") + .successHandler(customSuccessHandler) + .and().csrf().disable(); + + + + } + + + + +} + diff --git a/NewFileAdded/Prerequisites.md b/NewFileAdded/Prerequisites.md new file mode 100644 index 00000000..f0d106c5 --- /dev/null +++ b/NewFileAdded/Prerequisites.md @@ -0,0 +1,60 @@ +# Software Prerequisite: + +1. MySQL +2. Eclipse + +## Databases Setup: + +Step 1: Create Database name bank + +Step 2: Create Table name customer + +// Create a database +CREATE DATABASE BANK; + + +// Create table +CREATE TABLE `customer` ( + + `ac_no` int NOT NULL AUTO_INCREMENT, + + `cname` varchar(45) DEFAULT NULL, + + `balance` varchar(45) DEFAULT NULL, + + `pass_code` int DEFAULT NULL, + + PRIMARY KEY (`ac_no`), + + UNIQUE KEY `cname_UNIQUE` (`cname`) + +) ; +## Eclipse Project Setup: + +Create New Project +Create A package name banking + + +## File configuration + +Create a Connection class in the banking package + +## Step 1: Include JDBC Driver for MySQL + +// register jdbc Driver + +String mysqlJDBCDriver = "com.mysql.cj.jdbc.Driver"; + +Class.forName(mysqlJDBCDriver); + +## Step 2: Create Connection Class using MySQL username and password + +// Create Connection + +String url = "jdbc:mysql://localhost:3306/mydata"; + +String user = "root"; + +String pass = "123"; + +con = DriverManager.getConnection(url, user, pass); diff --git a/NewFileAdded/Readme.md b/NewFileAdded/Readme.md new file mode 100644 index 00000000..80d4870c --- /dev/null +++ b/NewFileAdded/Readme.md @@ -0,0 +1 @@ +Hii diff --git a/NewFileAdded/Server.java b/NewFileAdded/Server.java new file mode 100644 index 00000000..59fd32c5 --- /dev/null +++ b/NewFileAdded/Server.java @@ -0,0 +1,97 @@ +import java.net.*; + +import javax.sound.sampled.SourceDataLine; + +import java.io.*; + +class Server{ + +ServerSocket server; +Socket socket; + +BufferedReader br; +PrintWriter out; + + public Server(){ + try{server = new ServerSocket(7777); + System.out.println("Server is ready to accept connection"); + System.out.println("waiting..."); + socket=server.accept(); + + br = new BufferedReader(new InputStreamReader(socket.getInputStream())); + + out = new PrintWriter(socket.getOutputStream()); + + startReading(); + startWriting(); + + + + + } catch(Exception e ){};} + + +public void startReading(){ + Runnable r1=()->{ + System.out.println("reader started..."); + + try{ + while(true){ + + String msg = br.readLine(); + if(msg.equals("EXIT")){System.out.println("Client terminated the chatting"); + socket.close(); + break;} + + System.out.println("Client : "+msg); + + + } + } catch(Exception e){System.out.print("----Connection is Closed----");} + }; + + new Thread(r1).start(); +} + + + +public void startWriting(){ + Runnable r2=()->{ + System.out.println("Writer started..."); + + try{ + while(!socket.isClosed()){ + + BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); + + String content=br1.readLine(); + + out.println(content); + out.flush(); + + if(content.equals("EXIT")){ + socket.close(); + break; + } + + } + } catch(Exception e){System.out.print("----Connection is Closed----");}; + + }; + + new Thread(r2).start(); +} + + + + + + +public static void main(String[] args){ + System.out.println("This is server..going to start server"); + new Server(); +} + + + +} diff --git a/NewFileAdded/UserDetailsServiceImpl.java b/NewFileAdded/UserDetailsServiceImpl.java new file mode 100644 index 00000000..b6f609c0 --- /dev/null +++ b/NewFileAdded/UserDetailsServiceImpl.java @@ -0,0 +1,38 @@ +package com.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import com.model.User; + +import com.repository.UserRepository; + +@Service +public class UserDetailsServiceImpl implements UserDetailsService{ + + @Autowired + private UserRepository userRepository; + + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + + + //fetching user from + + User user = userRepository.getUserByEmail(username); + + if(user == null) + { + throw new UsernameNotFoundException("Could not found user !!"); + + } + CustomUserDetails customUserDetails = new CustomUserDetails(user); + + return customUserDetails; + } + +} diff --git a/NewFileAdded/about_new.dust b/NewFileAdded/about_new.dust new file mode 100644 index 00000000..b835046f --- /dev/null +++ b/NewFileAdded/about_new.dust @@ -0,0 +1,18 @@ + + + +{@if cond="'{device}'=='Desktop'"} + +{:else} + +{/if} + +

{title}

+

{subhead}

+ +

The BESTest todo app evar

+ +
Device string (debug): {device}
+ + + diff --git a/NewFileAdded/account.hbs b/NewFileAdded/account.hbs new file mode 100644 index 00000000..a55102f3 --- /dev/null +++ b/NewFileAdded/account.hbs @@ -0,0 +1,44 @@ + + +{{#if firstname}} +

Account details for: {{firstname}}

+
+

details saved

+
+{{else}} +

Account details missing

+{{/if}} + +
+
+
+
First name
+ +
+ +
Last name
+ +
+ +
Country
+ +
+ +
Phone number
+ +
+ +
Email
+ +
+ +
+ +
+
+ + +
+
\ No newline at end of file diff --git a/NewFileAdded/admin.ejs b/NewFileAdded/admin.ejs new file mode 100644 index 00000000..68db9645 --- /dev/null +++ b/NewFileAdded/admin.ejs @@ -0,0 +1,23 @@ +<% layout( 'layout' ) -%> + +

<%= title %>

+ +
+
+ <% if( granted == false ){ %> +
+
username
+ +
+
password
+ +
+ + +
+
+ <% } %> +
+
diff --git a/NewFileAdded/adminService.js b/NewFileAdded/adminService.js new file mode 100644 index 00000000..0ab6316a --- /dev/null +++ b/NewFileAdded/adminService.js @@ -0,0 +1,12 @@ +// @TODO use this adminService file once Snyk Code for VSCode +// is able to navigate to cross-file paths in the vuln description +/** +module.exports.adminLoginSuccess = function(redirectPage, res) { + console.log({redirectPage}) + if (redirectPage) { + return res.redirect(redirectPage) + } else { + return res.redirect('/admin') + } +} +*/ \ No newline at end of file diff --git a/NewFileAdded/authentication.component.spec.js b/NewFileAdded/authentication.component.spec.js new file mode 100644 index 00000000..3582667a --- /dev/null +++ b/NewFileAdded/authentication.component.spec.js @@ -0,0 +1,59 @@ +const assert = require('assert)') + +describe('Component Tests', () => { + describe('PasswordComponent', () => { + + let comp + let service + + test('should show error if passwords do not match', () => { + // GIVEN + comp.password = 'password1'; + comp.confirmPassword = 'password2'; + // WHEN + comp.changePassword(); + // THEN + assert(comp.doNotMatch).toBe('ERROR'); + assert(comp.error).toBeNull(); + assert(comp.success).toBeNull(); + }); + + test('should call Auth.changePassword when passwords match', () => { + // GIVEN + // deepcode ignore NoHardcodedPasswords/test: + comp.password = comp.confirmPassword = 'myPassword'; + + // WHEN + comp.changePassword(); + + // THEN + assert(service.save).toHaveBeenCalledWith('myPassword'); + }); + + test('should set success to OK upon success', function() { + // GIVEN + comp.password = comp.confirmPassword = 'myPassword'; + + // WHEN + comp.changePassword(); + + // THEN + expect(comp.doNotMatch).toBeNull(); + expect(comp.error).toBeNull(); + expect(comp.success).toBe('OK'); + }); + + test('should notify of error if change password fails', function() { + // GIVEN + comp.password = comp.confirmPassword = 'myPassword'; + + // WHEN + comp.changePassword(); + + // THEN + assert(comp.doNotMatch).toBeNull(); + assert(comp.success).toBeNull(); + assert(comp.error).toBe('ERROR'); + }); + }); +}); \ No newline at end of file diff --git a/NewFileAdded/bank.java b/NewFileAdded/bank.java new file mode 100644 index 00000000..782c9766 --- /dev/null +++ b/NewFileAdded/bank.java @@ -0,0 +1,99 @@ +package banking; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class bank { + public static void main(String args[]) //main class of bank + throws IOException + { + + BufferedReader sc = new BufferedReader( + new InputStreamReader(System.in)); + String name = ""; + int pass_code; + int ac_no; + int ch; + + while (true) { + System.out.println( + "\n ->|| Welcome to InBank ||<- \n"); + System.out.println("1)Create Account"); + System.out.println("2)Login Account"); + + try { + System.out.print("\n Enter Input:"); //user input + ch = Integer.parseInt(sc.readLine()); + + switch (ch) { + case 1: + try { + System.out.print( + "Enter Unique UserName:"); + name = sc.readLine(); + System.out.print( + "Enter New Password:"); + pass_code = Integer.parseInt( + sc.readLine()); + + if (bankManagement.createAccount( + name, pass_code)) { + System.out.println( + "MSG : Account Created Successfully!\n"); + } + else { + System.out.println( + "ERR : Account Creation Failed!\n"); + } + } + catch (Exception e) { + System.out.println( + " ERR : Enter Valid Data::Insertion Failed!\n"); + } + break; + + case 2: + try { + System.out.print( + "Enter UserName:"); + name = sc.readLine(); + System.out.print( + "Enter Password:"); + pass_code = Integer.parseInt( + sc.readLine()); + + if (bankManagement.loginAccount( + name, pass_code)) { + System.out.println( + "MSG : Logout Successfully!\n"); + } + else { + System.out.println( + "ERR : login Failed!\n"); + } + } + catch (Exception e) { + System.out.println( + " ERR : Enter Valid Data::Login Failed!\n"); + } + + break; + + default: + System.out.println("Invalid Entry!\n"); + } + + if (ch == 5) { + System.out.println( + "Exited Successfully!\n\n Thank You :)"); + break; + } + } + catch (Exception e) { + System.out.println("Enter Valid Entry!"); + } + } + sc.close(); + } +} diff --git a/NewFileAdded/bankmanagemment.java b/NewFileAdded/bankmanagemment.java new file mode 100644 index 00000000..f3cb9a65 --- /dev/null +++ b/NewFileAdded/bankmanagemment.java @@ -0,0 +1,229 @@ +package banking; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLIntegrityConstraintViolationException; +import java.sql.Statement; + +public class bankManagement { // these class provides all + // bank method + + private static final int NULL = 0; + + static Connection con = connection.getConnection(); + static String sql = ""; + public static boolean + createAccount(String name, + int passCode) // create account function + { + try { + // validation + if (name == "" || passCode == NULL) { + System.out.println("All Field Required!"); + return false; + } + // query + Statement st = con.createStatement(); + sql = "INSERT INTO customer(cname,balance,pass_code) values('" + + name + "',1000," + passCode + ")"; + + // Execution + if (st.executeUpdate(sql) == 1) { + System.out.println(name + + ", Now You Login!"); + return true; + } + // return + } + catch (SQLIntegrityConstraintViolationException e) { + System.out.println("Username Not Available!"); + } + catch (Exception e) { + e.printStackTrace(); + } + return false; + } + public static boolean + loginAccount(String name, int passCode) // login method + { + try { + // validation + if (name == "" || passCode == NULL) { + System.out.println("All Field Required!"); + return false; + } + // query + sql = "select * from customer where cname='" + + name + "' and pass_code=" + passCode; + PreparedStatement st + = con.prepareStatement(sql); + ResultSet rs = st.executeQuery(); + // Execution + BufferedReader sc = new BufferedReader( + new InputStreamReader(System.in)); + + if (rs.next()) { + // after login menu driven interface method + + int ch = 5; + int amt = 0; + int senderAc = rs.getInt("ac_no"); + ; + int receiveAc; + while (true) { + try { + System.out.println( + "Hallo, " + + rs.getString("cname")); + System.out.println( + "1)Transfer Money"); + System.out.println("2)View Balance"); + System.out.println("5)LogOut"); + + System.out.print("Enter Choice:"); + ch = Integer.parseInt( + sc.readLine()); + if (ch == 1) { + System.out.print( + "Enter Receiver A/c No:"); + receiveAc = Integer.parseInt( + sc.readLine()); + System.out.print( + "Enter Amount:"); + amt = Integer.parseInt( + sc.readLine()); + + if (bankManagement + .transferMoney( + senderAc, receiveAc, + amt)) { + System.out.println( + "MSG : Money Sent Successfully!\n"); + } + else { + System.out.println( + "ERR : Failed!\n"); + } + } + else if (ch == 2) { + + bankManagement.getBalance( + senderAc); + } + else if (ch == 5) { + break; + } + else { + System.out.println( + "Err : Enter Valid input!\n"); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + else { + return false; + } + // return + return true; + } + catch (SQLIntegrityConstraintViolationException e) { + System.out.println("Username Not Available!"); + } + catch (Exception e) { + e.printStackTrace(); + } + return false; + } + public static void + getBalance(int acNo) // fetch balance method + { + try { + + // query + sql = "select * from customer where ac_no=" + + acNo; + PreparedStatement st + = con.prepareStatement(sql); + + ResultSet rs = st.executeQuery(sql); + System.out.println( + "-----------------------------------------------------------"); + System.out.printf("%12s %10s %10s\n", + "Account No", "Name", + "Balance"); + + // Execution + + while (rs.next()) { + System.out.printf("%12d %10s %10d.00\n", + rs.getInt("ac_no"), + rs.getString("cname"), + rs.getInt("balance")); + } + System.out.println( + "-----------------------------------------------------------\n"); + } + catch (Exception e) { + e.printStackTrace(); + } + } + public static boolean transferMoney(int sender_ac, + int reveiver_ac, + int amount) + throws SQLException // transfer money method + { + // validation + if (reveiver_ac == NULL || amount == NULL) { + System.out.println("All Field Required!"); + return false; + } + try { + con.setAutoCommit(false); + sql = "select * from customer where ac_no=" + + sender_ac; + PreparedStatement ps + = con.prepareStatement(sql); + ResultSet rs = ps.executeQuery(); + + if (rs.next()) { + if (rs.getInt("balance") < amount) { + System.out.println( + "Insufficient Balance!"); + return false; + } + } + + Statement st = con.createStatement(); + + // debit + con.setSavepoint(); + + sql = "update customer set balance=balance-" + + amount + " where ac_no=" + sender_ac; + if (st.executeUpdate(sql) == 1) { + System.out.println("Amount Debited!"); + } + + // credit + sql = "update customer set balance=balance+" + + amount + " where ac_no=" + reveiver_ac; + st.executeUpdate(sql); + + con.commit(); + return true; + } + catch (Exception e) { + e.printStackTrace(); + con.rollback(); + } + // return + return false; + } +} diff --git a/NewFileAdded/connection.java b/NewFileAdded/connection.java new file mode 100644 index 00000000..12deec39 --- /dev/null +++ b/NewFileAdded/connection.java @@ -0,0 +1,29 @@ +package banking; + +import java.sql.Connection; +import java.sql.DriverManager; +// Global connection Class +public class connection { + static Connection con; // Global Connection Object + public static Connection getConnection() + { + try { + + + String mysqlJDBCDriver + = "com.mysql.cj.jdbc.Driver"; //jdbc driver + String url + = "jdbc:mysql://localhost:3306/mydata"; //mysql url + String user = "root"; //mysql username + String pass = "Pritesh4@"; //mysql passcode + Class.forName(mysqlJDBCDriver); + con = DriverManager.getConnection(url, user, + pass); + } + catch (Exception e) { + System.out.println("Connection Failed!"); + } + + return con; + } +} diff --git a/NewFileAdded/edit.ejs b/NewFileAdded/edit.ejs new file mode 100644 index 00000000..22b15a8b --- /dev/null +++ b/NewFileAdded/edit.ejs @@ -0,0 +1,33 @@ +<% layout( 'layout' ) -%> + +

<%= title %>

+
+
+
+ +
+
+ +<% todos.forEach( function ( todo ){ %> + <% if( todo._id == current ){ %> +
+ <% }else{ %> +
+ <% } %> + + <% if( todo._id == current ){ %> +
+ +
+ <% }else{ %> + <%= todo.content %> + <% } %> + + <% if( todo._id == current ){ %> + Delete + <% }else{ %> + Delete + <% } %> +
+<% }); %> +
diff --git a/NewFileAdded/index.ejs b/NewFileAdded/index.ejs new file mode 100644 index 00000000..fef7c6c3 --- /dev/null +++ b/NewFileAdded/index.ejs @@ -0,0 +1,24 @@ +<% layout( 'layout' ) -%> + + +
+ +

<%= title %>

+
+ +
+
+
+ +
+
+ +<% todos.forEach( function ( todo ){ %> + +<% }); %> +
diff --git a/NewFileAdded/layout.ejs b/NewFileAdded/layout.ejs new file mode 100644 index 00000000..eea8491b --- /dev/null +++ b/NewFileAdded/layout.ejs @@ -0,0 +1,28 @@ + + + + <%= title %> + + + + +
+ <%- body %> + +
+ + + diff --git a/NewFileAdded/layout.hbs b/NewFileAdded/layout.hbs new file mode 100644 index 00000000..849f6e16 --- /dev/null +++ b/NewFileAdded/layout.hbs @@ -0,0 +1,22 @@ + + + + <%= title %> + + + + +
+ {{{body}}} + +
+ + + diff --git a/NewFileAdded/mclient.java b/NewFileAdded/mclient.java new file mode 100644 index 00000000..412403c3 --- /dev/null +++ b/NewFileAdded/mclient.java @@ -0,0 +1,43 @@ +import java.util.*; +import java.net.*; +import java.io.*; + +public class mclient { + + public static void main(String s[]) throws Exception { + Socket s1 = null; + String line = null; + DataInputStream br = null; + DataInputStream is = null; + PrintWriter os = null; + try { + s1 = new Socket("localhost", 9999); + br = new DataInputStream(System.in); + is = new DataInputStream(s1.getInputStream()); + os = new PrintWriter(s1.getOutputStream()); + + } catch (IOException e) { + System.err.print("IO Exception"); + + } + System.out.println("Enter data to server (enter QUIT to end) :-> "+s1.getRemoteSocketAddress().toString()); + String res = null; + try { + line = br.readLine(); + while (line.compareTo("QUIT") != 0) { + os.println(line); + os.flush(); + res = is.readLine(); + System.out.println("server response :-> " + res); + line = br.readLine(); + } + is.close(); + os.close(); + br.close(); + s1.close(); + System.out.println("close connection "); + } catch (IOException e) { + System.out.println("socket read error"); + } + } +} diff --git a/NewFileAdded/mserver.java b/NewFileAdded/mserver.java new file mode 100644 index 00000000..020e4d0a --- /dev/null +++ b/NewFileAdded/mserver.java @@ -0,0 +1,63 @@ +import java.util.*; +import java.net.*; +import java.io.*; + +public class mserver { + + public static void main(String s[]) throws Exception { + Socket sa = null; + ServerSocket ss2 = null; + System.out.println("Host starts accepting response "); + try { + ss2 = new ServerSocket(9999); + } catch (IOException e) { + System.out.println("server error"); + } + while (true) { + try { + sa = ss2.accept(); + System.out.println("connetion established by"+ ss2.getInetAddress()); + ServerThread st = new ServerThread(sa); + st.start(); + } catch (Exception e) { + System.out.println("connetion error"); + } + } + } +} + +class ServerThread extends Thread { + String line = null; + DataInputStream is = null; + PrintWriter od = null; + Socket s1 = null; + + public ServerThread(Socket s) { + s1 = s; + } ++ + public void run() { + try { + + is = new DataInputStream(s1.getInputStream()); + od = new PrintWriter(s1.getOutputStream()); + + line = is.readLine(); + + while (!line.equals("QUIT")) { + od.println(line); + od.flush(); + + System.out.println("response to client " + line); + line = is.readLine(); + + } + is.close(); + od.close(); + s1.close(); + + } catch (IOException ie) { + System.out.println("socket close error"); + } + } +} \ No newline at end of file diff --git a/semgrep.yml b/semgrep.yml new file mode 100644 index 00000000..b7f18722 --- /dev/null +++ b/semgrep.yml @@ -0,0 +1,40 @@ +# Name of this GitHub Actions workflow. +name: Semgrep + +on: + # Scan changed files in PRs (diff-aware scanning): + pull_request: {} + # Scan on-demand through GitHub Actions interface: + workflow_dispatch: {} + # Scan mainline branches and report all findings: + push: + branches: ["master", "main"] + # Schedule the CI job (this method uses cron syntax): + schedule: + - cron: '20 17 * * *' # Sets Semgrep to scan every day at 17:20 UTC. + # It is recommended to change the schedule to a random time. + +jobs: + semgrep: + # User definable name of this GitHub Actions job. + name: semgrep/ci + # If you are self-hosting, change the following `runs-on` value: + runs-on: ubuntu-latest + + container: + # A Docker image with Semgrep installed. Do not change this. + image: returntocorp/semgrep + + # Skip any PR created by dependabot to avoid permission issues: + if: (github.actor != 'dependabot[bot]') + + steps: + # Fetch project source with GitHub Actions Checkout. + - uses: actions/checkout@v3 + # Run the "semgrep ci" command on the command line of the docker image. + - run: semgrep ci + env: + # Connect to Semgrep Cloud Platform through your SEMGREP_APP_TOKEN. + # Generate a token from Semgrep Cloud Platform > Settings + # and add it to your GitHub secrets. + SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}